我知道一些基本的 python,我決定嘗試制作一個不和諧的機器人,但未能讓機器人回應命令。我嘗試將“-ping”更改為“ping”并嘗試在我的不和諧服務器上輸入:
平-平
但他們都沒有做任何事情。此外,
console.log('This does not run');
不顯示在控制臺中。
我不太確定我錯在哪里。任何幫助,將不勝感激。謝謝!
const {Client, Intents} = require('discord.js');
const {token} = require('./config.json');
const client = new Client({intents:[Intents.FLAGS.GUILDS]});
const prefix = '-';
client.once('ready', () => {
console.log('Bot works');
});
client.on('message', message => {
console.log('This does not run');
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(token);
uj5u.com熱心網友回復:
我認為您需要GUILD_MESSAGES啟用意圖。您可以將其添加到客戶端建構式中的意圖串列中,如下所示:
const client = new Client({intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]});
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/368093.html
