久久久久久久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?)
主站蜘蛛池模板: 日韩a在线观看 | 尤物视频在线免费观看 | 在线观看国产网站 | 超级碰在线 | 在线看日韩 | www.99精品 | 美女视频一区二区三区 | 一区二区在线 | 免费看黄视频网站 | 超碰97人人人人人蜜桃 | 久久综合九色综合欧美狠狠 | 久色激情 | 亚洲综合视频 | 国产一区二区 | 久久亚洲一区二区三区四区 | 成人中文字幕av | 免费在线观看黄网站 | 免费一区在线 | 欧美视频日韩 | 亚洲三区在线观看 | 亚洲午夜av久久乱码 | 欧美日韩最新 | 久久久久国产精品午夜一区 | 亚洲天堂男人的天堂 | 亚洲一区二区三区在线 | 久久99国产精一区二区三区 | 国产成人精品综合 | 九色网址| 国产精品久久久久9999鸭 | 国产97久久 | 懂色中文一区二区在线播放 | 日韩a视频 | 精品成人 | 亚洲国产一区二区视频 | 欧美精品日韩精品国产精品 | 91精品国产91久久久久久丝袜 | 久久久久久99 | 亚洲一区 中文字幕 | 国产99久久精品一区二区300 | 亚洲一区二区三区四区av | 中文字幕伊人 |