首页 > 解决方案 > 如何通过 discord.js 发布到新的 NewsChannel

问题描述

我想让我的机器人能够发布到新的 ANNOUNCEMENTS_CHANNEL 功能 Discord.com 最近在整个平台上全球推出,但是 discord.js 文档在此功能上非常简约,但他们说NewsChannel extends TextChannel

我知道这确实有一个.send()但不确定如何确认它NewsChannel是一个在创建社区公会时激活的活动公告频道。

我会喜欢一些关于如何进行的提示和建议。

标签: javascriptnode.jsdiscord.js

解决方案


如果要确保频道是公告频道,请检查频道“新闻”的类型。从此,您可以轻松地将消息发送到该频道,就像您通常使用普通文本频道所做的那样。

let channel = message.mentions.channels.firts()
// ^^ An option if you are getting the channel from a mention in the message

if (channel.type !== "news") return
channel.send("your message")

https://discord.js.org/#/docs/main/stable/class/Channel


推荐阅读