【问题标题】:Discord Bot not responding to ping commandDiscord Bot 没有响应 ping 命令
【发布时间】:2022-01-04 22:37:33
【问题描述】:

我知道一些基本的python,我决定尝试制作一个不和谐的机器人,但未能让机器人响应命令。我尝试将“-ping”更改为“ping”并尝试在我的不和谐服务器上输入:

平 -ping

但两者都没有做任何事情。此外,

console.log('This does not run');

不显示在控制台中。

我不太确定我错在哪里。任何帮助,将不胜感激。谢谢!

const {Client, Intents} = require('discord.js');
const {token} = require('./config.json');
const client = new Client({intents:[Intents.FLAGS.GUILDS]});
const prefix = '-';



client.once('ready', () => {
   console.log('Bot works');
});


client.on('message', message => {
   console.log('This does not run');
   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'){
       message.channel.send('pong');
   }
});

client.login(token);

【问题讨论】:

标签: node.js discord.js


【解决方案1】:

我认为您需要启用 GUILD_MESSAGES 意图。您可以将其添加到客户端构造函数中的意图列表中,如下所示:

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

【讨论】:

  • 另外,记得在开发者门户中启用GUILD_MESSAGESintent。
猜你喜欢
  • 2020-12-15
  • 2021-08-28
  • 2020-02-03
  • 2021-02-17
  • 2023-03-09
  • 2021-04-17
  • 2021-12-16
相关资源
最近更新 更多