【问题标题】:discord.js bot not responding to commands [duplicate]discord.js 机器人不响应命令[重复]
【发布时间】:2021-11-10 00:44:58
【问题描述】:

我正在关注YouTube: how on how to code a Discord bot上的教程

(我对编码很陌生,想从某个地方开始,我还需要一个机器人)。

代码运行良好,直到我开始添加更多命令,例如 -play-leave。之后,机器人不会响应任何命令。

我已经尝试更改前缀,从头开始,只是复制粘贴他的代码到我的。 机器人上线,但几乎没有让他响应的代码。

这是我的代码:

const Discord = require('discord.js');
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('SaltSounds Is Online!');
});

client.on('message', message =>{
    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('my token');

【问题讨论】:

标签: javascript discord discord.js


【解决方案1】:

您需要这两个意图来接收消息:GUILDSGUILD_MESSAGES。你可以这样实现

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

【讨论】:

    猜你喜欢
    • 2021-11-21
    • 2021-08-30
    • 2021-09-04
    • 2021-07-23
    • 2020-08-21
    • 1970-01-01
    • 2021-08-09
    • 2021-10-06
    • 2021-04-18
    相关资源
    最近更新 更多