DiscordJS V13 对 dms 没有反应

DiscordJS V13 doesnt react to dms

我有一个非常基本的 discord 机器人的非常基本的代码

自从新的 discord.js 版本 13 开始,您需要声明意图。

我尝试使用位图 32767 执行此操作(基本上声明所有意图),但是发送消息时机器人不会触发“messageCreate”事件 在 dms 中,它仅适用于服务器。

开发者网站上的所有特权网关意图都已设置为 true。

我错过了什么?

const Discord = require("discord.js");
const allIntents = new Discord.Intents(32767);
const client = new Discord.Client({ intents: allIntents });


require("dotenv").config();
const botName = "Miku";

client.once("ready", () => {
    //gets executed once at the start of the bot
    console.log(botName + " is online!");
});


client.on("messageCreate", (message) => {
    console.log("got a message");
});


(async() => {
    //bot connects with Discord api
    client.login(process.env.TOKEN);
})();

您不能在直接消息中监听事件,除非它们直接 responses/replies/reactions 到初始消息。

例如,您可以向新成员发送消息并等待回复:

client.on('guildMemberAdd', member =>{
    member.send("Welcome to the server!");

    message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
    .then((collected) => {
       //Now, write your code here that handles the reactions. 
    });

但是无法在私信中监听事件。比如,client.on... 永远不会因为 DM 事件而触发。