久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

當我向我的機器人發送 DM 時,事件 messageCreate 沒

Event messageCreate not firing/emitting when I send a DM to my bot (discord.js v13)(當我向我的機器人發送 DM 時,事件 messageCreate 沒有觸發/發射(discord.js v13))
本文介紹了當我向我的機器人發送 DM 時,事件 messageCreate 沒有觸發/發射(discord.js v13)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我編寫了這段代碼來記錄發送到我的機器人的 DM:

I made this code for logging the DMs that are sent to my bot:

client.on('messageCreate', async message => {

    if (message.author.bot) return;

    const attachment = message.attachments.first()

    if (message.channel.type === 'DM') {
        console.log(message.content)

        const dmLogEmbed = new MessageEmbed()
            .setColor("RANDOM")
            .setTitle(`${message.author.tag} dmed the bot and said: `)
            .setDescription(message.content)
            .setFooter(`User's id: ${message.author.id}`)

        if (message.attachments.size !== 0) {
            dmLogEmbed.setImage(attachment.url)

        }

        client.channels.fetch("852220016249798756").then((channel) => {

            channel.send({ embeds: [dmLogEmbed] })

        })
    }

});

但是當更新到 discord.js v13 時它不再起作用了,因為我知道唯一的變化是dm"頻道類型不再是dm"而是DM",所以我將其更改為我的代碼,但它仍然無法正常工作,我真的不知道為什么.

But when updating to discord.js v13 it didn't work anymore, for what I understood the only change is that the 'dm' channel type isn't 'dm' anymore but 'DM', so I changed it in my code, but it is still not working and I don't really know why.

推薦答案

確保您的客戶意圖中有 DIRECT_MESSAGES.

Make sure you have DIRECT_MESSAGES in your client's intents.

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGES"] });

Discord API v8 中有一個重大更改.如需參考,請參閱此處.

There is a breaking change in the Discord API v8. For reference see here.

在 Discord API v8 及更高版本中,DM 頻道不會發出 CHANNEL_CREATE 事件,這意味著 discord.js 無法自動緩存它們.為了讓您的機器人接收 DM,必須啟用 CHANNEL 部分.

On Discord API v8 and later, DM Channels do not emit the CHANNEL_CREATE event, which means discord.js is unable to cache them automatically. In order for your bot to receive DMs, the CHANNEL partial must be enabled.

所以我們也需要啟用部分CHANNEL.請記住,在處理部分數據時,您通常希望獲取 數據,因為它不完整.但是,如果您使用的是 messageCreate 事件,這似乎不是您的情況.收到的 message 不是部分的,也不是 message.channel.要檢查是否有部分內??容,您可以使用 .partial 屬性.例如 Message.partialChannel.partial.

So we need to enable the partial CHANNEL as well. Keep in mind that when dealing with partial data, you often want to fetch the data, because it is not complete. However this doesn't seem to be your case, if you are using the messageCreate event. The message received is not partial nor message.channel. To check if something is partial, you can use the .partial property. For example Message.partial or Channel.partial.

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGES"], partials: ["CHANNEL"] });

現在它應該可以像舊的 discord.js v12 一樣工作了.

Now it should work as good old discord.js v12.

這篇關于當我向我的機器人發送 DM 時,事件 messageCreate 沒有觸發/發射(discord.js v13)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應)
Check if user ID exists in Discord server(檢查 Discord 服務器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創建我的第一個機器人,但總是錯誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機器人編寫事件/命令處理程序?)
How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
主站蜘蛛池模板: 欧美精品电影一区 | 伊人网综合在线观看 | 亚洲精品视频一区二区三区 | 免费国产黄网站在线观看视频 | 欧美日韩不卡合集视频 | 日韩一区二区三区精品 | 在线观看中文字幕视频 | 精品久久久久久久人人人人传媒 | 亚洲精品福利视频 | 97av在线| 99爱在线免费观看 | 一区二区三区av | 人操人人| 成人免费观看视频 | 久久91精品 | 久久精品成人一区 | 中文字字幕在线中文乱码范文 | 亚洲一区二区久久 | 国产精品久久久久久久久婷婷 | 中文字幕在线视频免费观看 | 成人高清视频在线观看 | 亚洲综合精品 | 中文字幕一区二区三区四区五区 | 99pao成人国产永久免费视频 | 国产在线一区二区三区 | 亚洲国产精品久久久 | 久久久久久成人 | 中文字幕在线视频网站 | 亚洲精品久久久久久一区二区 | 色在线视频网站 | 欧美一页 | 成人av免费在线观看 | 欧美亚洲视频在线观看 | 国产在线www | 精品粉嫩aⅴ一区二区三区四区 | 中文字幕一区二区三区四区五区 | 有码一区 | 91精品久久久久久久久久入口 | 国产在线视频三区 | h视频在线观看免费 | 91麻豆蜜桃一区二区三区 |