【发布时间】: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');
【问题讨论】:
-
你使用的是什么版本的 discord.js?
-
你的客户意图是空的,你有没有尝试添加意图来接收公会消息
-
@MrMythical 我使用的是 13.1.0 版
-
@Elitezen 我不知道真正的意图是什么,你有什么我可以放进去的吗?也是的,我有,但没有那行代码。
标签: javascript discord discord.js