【问题标题】:Make a cloned channel in same position as the original在与原始通道相同的位置创建一个克隆通道
【发布时间】:2021-06-29 22:05:58
【问题描述】:

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

这是我的代码:

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))
  }
};

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    频道具有position 属性,因此您可以使用.setPosition() 方法将克隆频道的位置设置为此数字。 .clone()方法解析后即可获取克隆通道:

    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,
        ),
      );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      • 2021-02-09
      • 2018-11-16
      • 2012-05-03
      • 1970-01-01
      相关资源
      最近更新 更多