【问题标题】:Discord bot not responding/reacting to anything (JS)Discord bot 没有响应/对任何东西做出反应(JS)
【发布时间】:2021-11-17 06:40:04
【问题描述】:

所以我是不和谐机器人世界的新手,想尝试一下这个新挑战。在看了一些教程和阅读了一些帖子后,我的基础开始运行,但现在我的问题是机器人在启动后对任何内容都没有反应......

const Discord = require('discord.js');
const { token } = require('./config.json');

const intents = new Discord.Intents('GUILDS', 'GUILDS_MESSAGES');
const client = new Discord.Client({ intents });

const prefix = '-';

const fs = require('fs');

client.commands = new Discord.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.name, command);
}

client.once('ready', () => {
  console.log('Ready!');
});

client.on('message', (message) => {
  console.log('made it!');
  if (!message.content.startsWith(prefix) || message.author.bot) return;

  const args = message.content.slice(prefix.length).split(/ +/);
  const command = args.shift().toLowerCase();

  if (command === 'ping') {
    client.commands.get('ping').execute(message, args);
  }
});

client.login(token);

它所做的只是显示:“准备好了!”在控制台中。 在那之后,它不再对任何东西做出反应。不在discord上,也不在控制台中。

【问题讨论】:

  • 您能否指出您提供的代码中您认为应该使您的机器人对消息做出反应的特定行?
  • 几乎一直到底部:client.on('message', message => { console.log('made it!');
  • 我相信公会消息的意图是"GUILD_MESSAGES"

标签: javascript node.js discord.js bots


【解决方案1】:

这可能是因为您以错误的方式设置 Intent。

尝试替换:

const Discord = require('discord.js');

const intents = new Discord.Intents('GUILDS', 'GUILDS_MESSAGES');
const client = new Discord.Client({ intents });

与:

const { Client, Intents } = require('discord.js');
const client = new Client({
    intents: [
       Intents.FLAGS.GUILDS,
       Intents.FLAGS.GUILD_MESSAGES,
    ]
});

您也可以使用intents calculator

另外,使用messageCreate 代替message

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 2021-12-16
    • 2021-04-15
    • 1970-01-01
    • 2022-01-04
    • 2019-06-07
    • 2020-07-27
    • 2021-06-13
    相关资源
    最近更新 更多