首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >侦听DM通道discord.js中的discord.js事件

侦听DM通道discord.js中的discord.js事件
EN

Stack Overflow用户
提问于 2022-11-24 18:05:44
回答 2查看 31关注 0票数 0

我见过很多这个问题,我觉得我试过很多建议,但我不能让它起作用。现在,我只是记录messageCreate事件,但它无法工作。我将非常感谢你的帮助。

这是我的密码:

如你所见,我试过几件事^^

代码语言:javascript
复制
const { GatewayIntentBits, Partials, Guilds, Events } = require('discord.js');
const Discord = require('discord.js');

const Client = new Discord.Client({
    intents: [
        /* GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.DirectMessages, 
        GatewayIntentBits.DirectMessageTyping,
        GatewayIntentBits.MessageContent, */

        'Guilds', 'GuildMessages', 'DirectMessages', 'MessageContent'

    ],
    partials: [
        /* Partials.Channel, 
        Partials.GuildMember,
        Partials.Message,
        Partials.MessageReaction, 
        Partials.User,
        Partials.GuildMessages,
        Discord.PartialGroupDMChannel */

        "CHANNEL", "GUILD_MEMBER", "MESSAGES", "MESSAGE_REACTION", "USER", "DMCHANNEL"
    ]
});


Client.on('messageCreate', async message => {
    console.log('messageCreate event');
};

我尝试过不同的方法来实现正确的意图和部分,但我即将失去理智。

EN

回答 2

Stack Overflow用户

发布于 2022-11-24 19:27:12

您必须从djs idk导入客户端,如果另一件事情能够工作,但我这样做的方法是,并在messageCreate中将客户端更改为客户端。

代码语言:javascript
复制
const { Client, GatewayIntentBits, Partials, Guilds, Events } = require('discord.js');
const Discord = require('discord.js');

const myIntents = new IntentsBitField();
myIntents.add(GatewayIntentBits.GuildMembers,GatewayIntentBits.GuildMessages,GatewayGatewayIntentBits.DirectMessages,GatewayIntentBits.DirectMessageTyping,GatewayIntentBits.Guilds,GatewayIntentBits.MessageContent);
const client = new Discord.Client({ partials: [Partials.Message, Partials.Channel, Partials.MessageReaction, Partials.User,Partials.GuildMessages, Discord.PartialGroupDMChannel], intents: myIntents }); 
票数 0
EN

Stack Overflow用户

发布于 2022-11-24 19:41:21

将其添加到您的主/bot.js中

代码语言:javascript
复制
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
 intents: [
  GatewayIntentBits.Guilds,
  GatewayIntentBits.GuildMessages,
  GatewayIntentBits.MessageContent,
  GatewayIntentBits.GuildMembers
  GatewayIntentBits.DirectMessages,
  GatewayIntentBits.DirectMessageTyping,
  GatewayIntentBits.DirectMessageReactions]
});

module.exports = client;

如果使用的是eventHandler,则创建"messageCreate.js“文件并粘贴此代码

代码语言:javascript
复制
const client = require("YOUR_MAIN_FILE_PATH"); 
client.on("messageCreate", async(message)=>{
    //Your code
})

一些有用的网站:

  1. https://discord-api-types.dev/api/discord-api-types-v10/enum/GatewayIntentBits -> For GatewayIntentBits Information
  2. https://discord.js.org/#/docs/discord.js/main/general/welcome -> For Discord.js documentation
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74564760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档