所以我正在學習 discord.Js 并試圖弄清楚為什么我的 message.reply 功能不起作用。我為機器人創建了一個事件來監聽訊息,當發送內容為“hello”的訊息時,它應該回復“hello buddy”,代碼如下:
require('dotenv').config()
const discord = require('discord.js')
const client = new discord.Client({
intents: []
});
client.login(process.env.TOKEN);
client.on('ready', () => {
console.log(`${client.user.tag} has logged in`);
});
client.on('message', function(message){
if(message.content === 'hello') {
message.reply('hello buddy')
}
});
discord 中的機器人具有在我正在測驗它的服務器中發送訊息所需的所有權限。
uj5u.com熱心網友回復:
您的機器人未檢測到訊息。你的需要GUILDS和GUILD_MESSAGES意圖
const client = new discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES"]
})
此外,該message事件已被棄用。使用messageCreate替代
client.on('messageCreate', (message) => {
if(message.content === 'hello') {
message.reply('hello buddy')
}
})
請注意,我使用了箭頭函式。它們是更清晰的語法,你應該在回呼中使用它們
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/366117.html
標籤:javascript 不和谐.js
