【发布时间】:2022-01-07 05:34:26
【问题描述】:
命令未运行,我收到“交互失败”错误。
请告诉我哪个文件给出了错误,我该怎么做?
index.js:
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
client.once('ready', () => {
console.log('봇이 준비됐습니다!');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return interaction.reply({content: '없는 명령어입니다...', ephemeral: true });
const command = client.commands.get(interaction.commandName);
if (!command) return interaction.reply({ content: '명령을 실행하는 데 실패했습니다...', ephemeral: true });
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
return interaction.reply({ content: '명령을 실행하는 데 실패했습니다...', ephemeral: true });
}
});
s();
keepAlive();
client.login(token);
命令/help.js:
async execute(interaction) {
const helpembed = new MessageEmbed()
.setColor('red')
.setTitle('명령어')
return interaction.reply({embeds: [helpembed]});
},
【问题讨论】:
标签: javascript node.js discord.js