Discord.js 查找频道时的问题
Posted
技术标签:
【中文标题】Discord.js 查找频道时的问题【英文标题】:Discord.js issue at finding channel 【发布时间】:2022-01-06 20:02:45 【问题描述】:我正在尝试发出验证命令,但我一直卡在机器人上说“请输入有效频道!”即使频道名称有效。
let channel = message.mentions.channels.first() ||
message.guild.channels.cache.get(args[0]) ||
message.guild.channels.cache.find(c => c.name.toLowerCase() ===
args[0].toLocaleLowerCase());
if (!channel || channel.type !== 'text') return message.channel.send("**Please Enter A Valid Channel!**");
示例: Discord Example code
不介意提及角色。是为了在反应的时候被赋予一个角色
【问题讨论】:
你使用的是什么版本的 discord.js? 【参考方案1】:discord.js v13 频道类型已更改:
channel type | v12 | v13 |
---|---|---|
DM channel | dm |
DM |
group DM channel | N/A | GROUP_DM |
guild text channel | text |
GUILD_TEXT |
guild text channel's public thread channel | N/A | GUILD_PUBLIC_THREAD |
guild text channel's private thread channel | N/A | GUILD_PRIVATE_THREAD |
guild voice channel | voice |
GUILD_VOICE |
guild stage voice channel | N/A | GUILD_STAGE_VOICE |
guild category channel | category |
GUILD_CATEGORY |
guild news channel | news |
GUILD_NEWS |
guild news channel's public thread channel | N/A | GUILD_NEWS_THREAD |
guild store channel | store |
GUILD_STORE |
generic channel of unknown type | unknown |
UNKNOWN |
此表取自this answer,由@Zsolt Meszaros制作
将您的代码更改为:
if (!channel || channel.type !== "GUILD_TEXT") return message.channel.send("**Please Enter A Valid Channel!**")
【讨论】:
以上是关于Discord.js 查找频道时的问题的主要内容,如果未能解决你的问题,请参考以下文章