我正在尝试创建一个命令,该命令将通过/rename
重命名该命令所使用的当前通道。在discord.js文档中,它说只需写入:
channel
.setName('not_general')
.then((newChannel) => console.log(`Channel's new name is ${newChannel.name}`))
.catch(console.error);
但是测试的时候显示交互失败。有人知道怎么做吗?
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
等待bot更改通道名称。
同样,没有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);
}
},
};