![](/img/trans.png)
[英]Discord.js says "message is empty" but console.log shows data
[英]I m not getting Dms console.log on discord.js npmjs plugin
"messageCreate"
事件中的console.log()
在發送 DM 時未觸發。
const Client = new Discord.Client({
intents: [
"GUILDS",
"GUILD_MESSAGES",
"DIRECT_MESSAGES"
]
})
Client.on('messageCreate', (msg) => {
msgArray = msg.content.toLowerCase().split(' ')
if (msgArray[0] == "/botmsg"){
Client.users.fetch(msgArray[1], false).then((user) => {
user.send(msgArray[2]);
});
} else {
console.log(msg.content);
}
})
Client.login('token hidden')
我的目標是在收到 DM 時記錄消息,我該怎么做?
使用 discord.js v13 您需要啟用部分CHANNEL
,因此您的 Client 必須是
const Client = new Discord.Client({
intents: [
"GUILDS",
"GUILD_MESSAGES",
"DIRECT_MESSAGES"
],
partials: [
"CHANNEL"
]
})
您應該將console.log
function 放在代碼的“真實”部分。
if (msgArray[0] == "/botmsg"){
Client.users.fetch(msgArray[1], false).then((user) => {
user.send(msgArray[2]);
});
console.log(msg.content);
} else {
console.log(msg.content);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.