繁体   English   中英

我将如何编写命令来重命名命令用于 DiscordJS v13 的当前频道?

[英]How would I write a command to rename the current channel the command is used in with DiscordJS v13?

我正在尝试创建一个命令,该命令将通过/rename命令在其中使用的当前频道。 在 discord.js 文档中,它说只写:

channel
  .setName('not_general')
  .then((newChannel) => console.log(`Channel's new name is ${newChannel.name}`))
  .catch(console.error);

但是测试的时候说交互失败。 有谁知道这个怎么到go?

module.exports = {
  name: 'rename',
  description: 'Renames current channel',
  permission: 'ADMINISTRATOR',

  /**
   *
   * @param {CommandInteraction} interaction
   */
  async execute(interaction) {
    channel
      .setName('not_general')
      .then((newChannel) =>
        console.log(`Channel's new name is ${newChannel.name}`),
      )
      .catch(console.error);

    changeEmbed = new MessageEmbed()
      .setColor('#5665da')
      .setTitle('Ticket Update')
      .setDescription(`Ticket Channel Name Set To ${newChannel}`)
      .setTimestamp();

    interaction.reply({ embeds: [changeEmbed], ephemeral: true });
  },
};

我认为您还会在控制台上收到一条错误消息,因为您不能在then()之外使用newChannel变量。 您已经在使用async ,您可以使用await来等待机器人更改频道名称。

此外,没有channel变量。 您指的是interaction.channel吗? 这是发送交互的渠道。

module.exports = {
  name: 'rename',
  description: 'Renames current channel',
  permission: 'ADMINISTRATOR',

  /**
   *
   * @param {CommandInteraction} interaction
   */
  async execute(interaction) {
    try {
      let newChannel = await interaction.channel.setName('not_general');
      
      console.log(`Channel's new name is ${newChannel.name}`);

      let changeEmbed = new MessageEmbed()
        .setColor('#5665da')
        .setTitle('Ticket Update')
        .setDescription(`Ticket Channel Name Set To ${newChannel}`)
        .setTimestamp();

      interaction.reply({ embeds: [changeEmbed], ephemeral: true });
    } catch (error) {
      console.error(error);
    }
  },
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM