[英]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.