【发布时间】:2021-11-17 06:40:04
【问题描述】:
所以我是不和谐机器人世界的新手,想尝试一下这个新挑战。在看了一些教程和阅读了一些帖子后,我的基础开始运行,但现在我的问题是机器人在启动后对任何内容都没有反应......
const Discord = require('discord.js');
const { token } = require('./config.json');
const intents = new Discord.Intents('GUILDS', 'GUILDS_MESSAGES');
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('Ready!');
});
client.on('message', (message) => {
console.log('made it!');
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') {
client.commands.get('ping').execute(message, args);
}
});
client.login(token);
它所做的只是显示:“准备好了!”在控制台中。 在那之后,它不再对任何东西做出反应。不在discord上,也不在控制台中。
【问题讨论】:
-
您能否指出您提供的代码中您认为应该使您的机器人对消息做出反应的特定行?
-
几乎一直到底部:client.on('message', message => { console.log('made it!');
-
我相信公会消息的意图是
"GUILD_MESSAGES"
标签: javascript node.js discord.js bots