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

如何在 Discord.js 中檢查消息是否為 DM?

How do I check if a message is a DM in Discord.js?(如何在 Discord.js 中檢查消息是否為 DM?)
本文介紹了如何在 Discord.js 中檢查消息是否為 DM?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

目前我使用的是最新版本的 Discord.js (v13.1.0).

Currently I am using the latest version of Discord.js (v13.1.0).

我希望能夠檢測某條消息是否是 DM.我嘗試制作 messageCreate 事件并執行 if 語句來檢查頻道是否為 DM

I want to be able to detect if a certain message is a DM. I tried making a messageCreate event and did an if statement to check if the channel is a DM

client.on('messageCreate', message => {
   if (message.channel.type == 'DM') {
      console.log('Dm recieved!')
   }
})

由于某種原因,這不起作用.所以我不知道會發生什么.

This for some reason didn't work. So I have no idea what will.

這是我的意圖:

[Intents.FLAGS.GUILDS、Intents.FLAGS.GUILD_MESSAGES、Intents.FLAGS.GUILD_MESSAGE_REACTIONS、Intents.FLAGS.DIRECT_MESSAGES]

順便說一句,事件確實起作用了:

Btw, the event does work:

client.on('messageCreate', message => {
   console.log('Event')
}

推薦答案

我之前也遇到過這個問題;我深入研究了 discord.js v12 和 v13 之間的變化并找出了原因.

I had this issue earlier as well; I dug into the changes between discord.js v12 and v13 and figured out why.

如 這里在 rel="nofollow noreferrer">discordjs.guide 專門介紹更新之間的重大更改的網頁:

As seen here on the discordjs.guide webpage dedicated to the breaking changes between the updates:

在 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.

對于處理 DM 消息的非常重要的功能,該通知很難找到.它只直接提到了 CHANNEL_CREATE 事件,但基本上它的意思是您的機器人 無法 根本無法接收 DM,除非 CHANNEL 部分是在您的客戶端選項中啟用.

For the very important feature of handling DM messages, that notice was pretty difficult to find. It only directly mentions the CHANNEL_CREATE event, but basically what it means is that your bot is unable to receive DMs at all unless the CHANNEL partial is enabled in your client options.

以下是您將如何做到這一點的示例:

Here is an example of how you would do that:

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

您需要將該 partials 屬性添加到您的 Client 構造函數中才能接收 DM.這樣做后,您的代碼將正常工作.

You need to add that partials property to your Client constructor in order to receive DMs. After doing so, your code will work properly.

這篇關于如何在 Discord.js 中檢查消息是否為 DM?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 久草成人 | 日韩av在线免费 | 国产成人福利在线观看 | 一区二区三区视频在线观看 | 午夜小电影 | 日韩精品专区在线影院重磅 | 日韩国产一区 | 国产情侣激情 | 日韩欧美亚洲 | 91传媒在线观看 | 精品日韩在线 | 欧美在线精品一区 | 国产精品国产三级国产aⅴ无密码 | 日本中文字幕一区 | 九九伊人sl水蜜桃色推荐 | 亚洲精品在线免费观看视频 | 精品日韩在线 | 久久欧美精品 | 亚洲第一av | 男人天堂手机在线视频 | 龙珠z在线观看 | 特黄视频 | av资源中文在线 | 美女福利视频网站 | 午夜精品一区二区三区在线视频 | 91精品国产综合久久久久蜜臀 | 91av免费观看 | 国产成人福利 | 国产aⅴ精品 | 国产乱码精品一区二区三区五月婷 | 欧美一区二区三区在线播放 | 97碰碰碰| 中文字幕视频在线观看 | 国产午夜精品一区二区三区四区 | 日日操av | 欧美videosex性极品hd | 丝袜美腿一区二区三区动态图 | 怡红院怡春院一级毛片 | 久久久av | 成人免费xxxxx在线视频 | 日韩在线一区二区三区 |