简体   繁体   English

Discord 机器人没有响应 ping 命令

[英]Discord Bot not responding to ping command

I know some basic python and I decided to try my hand at making a discord bot, but failed to get the bot to respond to a command.我知道一些基本的 python 并且我决定尝试制作 discord 机器人,但未能让机器人响应命令。 I tried changing the '-ping' to 'ping' and tried typing on my discord server:我尝试将“-ping”更改为“ping”并尝试在我的 discord 服务器上输入:

ping -ping平平

but neither did anything.但两者都没有做任何事情。 Furthermore,此外,

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

does not show up in console.没有出现在控制台中。

I'm not quite sure where I wrong.我不太确定我错在哪里。 Any help would be appreciated.任何帮助,将不胜感激。 Thanks!谢谢!

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

I think you need the GUILD_MESSAGES intent enabled.我认为您需要启用GUILD_MESSAGES意图。 You can add it to the list of intents in the client constructor, like so:您可以将其添加到客户端构造函数中的意图列表中,如下所示:

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

thank you very much i had the same issue but resolved it thanks to your suggestion非常感谢我有同样的问题,但感谢您的建议解决了

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

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