如何获取Discord论坛标签?新增论坛时标签获取失败求助
正确获取Discord论坛频道标签的方法
你的代码里有几个关键问题导致拿不到标签:
- 你用
thread.id去查找频道,但thread.id是论坛帖子(线程)的ID,不是论坛频道本身的ID thread.guild.channels.guild是错误的属性路径,完全没必要这么写
要获取论坛频道的标签,核心是找到帖子所属的父论坛频道,再调用availableTags方法,具体步骤如下:
修正后的代码示例
discord.on('threadCreate', async (thread) => { // 先判断这个线程是否属于论坛频道,避免处理其他类型的线程 if (thread.parent?.type !== 'GUILD_FORUM') return; // 获取父论坛频道:优先用缓存里的parent,缓存没命中就主动fetch const forumChannel = thread.parent ?? await discord.channels.fetch(thread.parentId); // 现在就能拿到该论坛的所有可用标签了 const availableTags = forumChannel.availableTags; console.log('论坛可用标签:', availableTags); });
关键说明
thread.parent直接指向该帖子所属的父论坛频道,不需要自己去缓存里瞎找ID- 加个类型判断
GUILD_FORUM,防止处理普通文本频道的线程 - 如果
thread.parent为undefined(缓存没加载到),用channels.fetch()主动获取频道数据,确保能拿到标签信息
内容的提问来源于stack exchange,提问作者Ray
相关产品推荐
相关产品推荐

