gpt4 book ai didi

javascript - 在与原始 channel 相同的位置制作克隆 channel

转载 作者:行者123 更新时间:2023-12-04 03:35:52 33 4
gpt4 key购买 nike

我在我的 discord.js 机器人中创建了 nuke 命令,它创建了具有相同名称、权限、主题等的 channel ,并删除了“原始” channel 。但是有一个问题,如何使 channel 与“原始”处于同一位置?

这是我的代码:

module.exports = {
name: 'nuke',
aliases: [ 'clearall' ],
guildOnly: true,
permissions: [ 'MANAGE_MESSAGES', 'MANAGE_CHANNELS' ],
clientPermissions: [ 'MANAGE_CHANNELS' ],
group: 'moderation',
description: 'Removes all messages in the channel (Deletes the old channel and makes a copy of it with permissions intact)',
examples: [
'nuke',
'clearall'
],
run: async (client, message) => {

await message.channel.send(`This will remove all conversation in this channel and may cause conflict for bots using ID to track channels. Continue?`);

const filter = _message => message.author.id === _message.author.id && ['y','n','yes','no'].includes(_message.content.toLowerCase());
const options = { max: 1, time: 30000, errors: ['time'] };
const proceed = await message.channel.awaitMessages(filter, options)
.then(collected => ['y','yes'].includes(collected.first().content.toLowerCase()) ? true : false)
.catch(() => false);

if (!proceed){
return message.channel.send(`\\❌ | **${message.author.tag}**, you cancelled the nuke command!`);
};

return message.channel.send(`The nuke has been deployed, saying goodbye to **#${message.channel.name}** in 10`)
.then(() => setTimeout(() => message.channel.clone()
.then(() => message.channel.delete().catch(() => null)), 10000))
}
};

最佳答案

channel 有一个 position属性,因此您可以使用 .setPosition() 将克隆 channel 的位置设置为此数字方法。解析.clone()方法后即可得到克隆的 channel :

return message.channel
.send(
`The nuke has been deployed, saying goodbye to **#${message.channel.name}** in 10`,
)
.then(() =>
setTimeout(
() =>
message.channel.clone().then((clonedChannel) => {
const originalPosition = message.channel.position;

message.channel.delete().catch(() => null);
clonedChannel.setPosition(originalPosition);
}),
10000,
),
);

关于javascript - 在与原始 channel 相同的位置制作克隆 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66929402/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com