【发布时间】:2021-10-23 16:14:58
【问题描述】:
我以前搜索过这个但我什么也没得到,即使有很多问题非常相似。如果我发布相同的内容,我提前道歉。
这是我第一次创建机器人。我跟随这两个视频达到了这一点。
https://www.youtube.com/watch?v=nTGtiCC3iQM&
问题在于,即使机器人处于开启状态,它也无法捕捉到 ping 命令。这是最开始。我无法继续对机器人进行编程,因为他无法捕捉任何命令。
这是我的 main.js 代码。我唯一更改的是将new Discord.client(); 更改为new Discord.Client({ intents: 100 });,因为它似乎最近发生了变化。
我仍然不知道什么是意图以及我应该在那里输入什么数字,但是当我写下 node . 时,机器人似乎打开了。
const Discord = require('discord.js');
const client = new Discord.Client({ intents: 100 });
// idk which number of intents should I put here
const prefix = '-';
client.once('ready', () => {
console.log('Ivancódigo funcionando!');
});
client.on('message', message =>{
/*if(message.content.startsWith(`${prefix}ping`)){
message.channel.send('pong!');*/
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');
当我在 discord 的文本框中输入 -ping 时,我仍然没有得到任何回应。我已经尝试了许多代码,但仍然相同,但我清理了大部分代码以保持您阅读的舒适,只保留重要的东西。错误一定是在 Discord 收到此代码说明的任何地方,但我不知道如何解决。
我哪里出错了?提前致谢。
【问题讨论】:
标签: javascript discord command bots