我正在使用 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模板网!
使用 discord.js 检测图像并响应Using discord.js to detect image and respond(使用 discord.js 检测图像并响应)
检查 Discord 服务器中是否存在用户 IDCheck if user ID exists in Discord server(检查 Discord 服务器中是否存在用户 ID)
公会成员添加不起作用(discordjs)Guild Member Add does not work (discordjs)(公会成员添加不起作用(discordjs))
使用 REPLIT 创建我的第一个机器人,但总是错误Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 创建我的第一个机器人,但总是错误 Discord.JS)
如何为我的 Discord.js 机器人编写事件/命令处理程How do I code event/command handlers for my Discord.js bot?(如何为我的 Discord.js 机器人编写事件/命令处理程序?)
如何从 Discord.js 中的用户名中查找用户 ID?How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)