本文介紹了我的不和諧機器人代碼正在運行,但沒有響應我的命令的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我是編程專業的大三學生.我知道 node.js 并且想為不和諧寫我自己的機器人.
I am a junior in programming. I know node.js and want to write my own bot for discord.
下面寫的我的代碼不起作用.你能幫我解決這個問題嗎?
My code which is written below doesn't work. Can you help me with this?
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);
推薦答案
GUILDS
Intent 不足以接收消息.您還需要 GUILD_MESSAGES
消息意圖:
GUILDS
intent is not enough to receive messages. You will also need GUILD_MESSAGES
intent for messages:
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
})
這篇關于我的不和諧機器人代碼正在運行,但沒有響應我的命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!