繁体   English   中英

Discord 机器人没有响应 ping 命令

[英]Discord Bot not responding to ping command

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

平平

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

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);

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

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

非常感谢我有同样的问题,但感谢您的建议解决了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM