本文介绍了检查消息是否从 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:

频道类型v12v13
DM频道dmDM
群 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 发送不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 02:06