問題描述
我正在使用 Discord.js v12 并嘗試檢查消息是否是從 DM 發送的,但它對我不起作用,我已經嘗試過這種方法:
I am using Discord.js v12 and trying to check if a message was sent from a DM but it doesn't work for me, I have tried this method:
if (msg.channel.type === 'dm')
這在幾個月前還可以正常工作,但現在不行了.當我嘗試 console.log(msg.channel.type)
時,它只返回文本,當機器人收到 DM 時不返回 dm,我找不到任何解決方案.
This was working fine couple months ago but it doesn't work anymore. When i try console.log(msg.channel.type)
it only returns text and doesn't return dm when the bot gets an DM and I can't find any solutions for this.
推薦答案
你確定你沒有更新你的 discord.js 版本,你還在使用 v12 嗎?
Are you sure you haven't updated your discord.js version and you're still using v12?
v13 中的頻道類型現在是大寫的,并且符合 Discord 的命名約定.請參閱下面的更改:
Channel types in v13 are now uppercase and align with Discord's naming conventions. See below the changes:
頻道類型 | v12 | v13 |
---|---|---|
DM頻道 | dm | DM |
群 DM 頻道 | 不適用 | GROUP_DM |
公會文字頻道 | 文本 | GUILD_TEXT |
公會文字頻道的公共話題頻道 | 不適用 | GUILD_PUBLIC_THREAD |
公會文字頻道的私信頻道 | 不適用 | GUILD_PRIVATE_THREAD |
公會語音頻道 | 語音 | GUILD_VOICE |
公會舞臺語音頻道 | 不適用 | GUILD_STAGE_VOICE |
公會分類頻道 | 類別 | GUILD_CATEGORY |
公會新聞頻道 | 新聞 | GUILD_NEWS |
公會新聞頻道的公共話題頻道 | 不適用 | GUILD_NEWS_THREAD |
公會商店頻道 | 存儲 | GUILD_STORE |
未知類型的通用頻道 | 未知 | 未知 |
這篇關于檢查消息是否從 DM 發送不工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!