不一致机器人没有回复消息
本文介绍了不一致机器人没有回复消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试设置不一致机器人,通过遵循文档,我已经能够设置斜杠命令,但未能使该机器人答复服务器上的消息。
以下是我用来从docs设置斜杠命令的代码。
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const commands = [{
name: 'ping',
description: 'Replies with Pong!'
}];
const rest = new REST({ version: '9' }).setToken('token');
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
之后,我用以下代码设置了机器人:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('interactionCreate', async interaction => {
// console.log(interaction)
if (!interaction.isCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
// await interaction.reply(client.user + '