Iva*_*pov 2 javascript node.js discord discord.js
我是一名编程大三学生。我了解 Node.js,并且想编写自己的 Discord 机器人。
我下面写的代码不起作用。你能帮我解决这个问题吗?
const { Client, Intents } = require('discord.js');
const config = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message=>{
if(!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
}
})
client.login(config.token);
Run Code Online (Sandbox Code Playgroud)
GUILDS意图不足以接收消息。您还需要GUILD_MESSAGES消息意图:
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
382 次 |
| 最近记录: |