Checking if a message was sent from a DM not working(检查消息是否从 DM 发送不工作)
问题描述
我正在使用 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 发送不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查消息是否从 DM 发送不工作


基础教程推荐
- 检查 HTML5 拖放文件类型 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01