愿所有的美好和期待都能如约而至

不一致机器人没有回复消息

发布时间:  来源:互联网  作者:匿名  标签:discord discord.js error Discord bot is not replying to messages exception IT资讯   热度:37.5℃

本文介绍了不一致机器人没有回复消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试设置不一致机器人,通过遵循文档,我已经能够设置斜杠命令,但未能使该机器人答复服务器上的消息。

以下是我用来从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 + '

勇敢去编程!

勇敢的热爱编程,未来的你一定会大放异彩,未来的生活一定会因编程更好!

TOP