discord - 每次我要进行更新时,如何让我的机器人发送一条消息,以便我的客户知道?(discord.js)
问题描述
我需要知道如何做到这一点,所以每当我对我的机器人进行更新时,它会在一个名为公告的频道中向每个服务器发送一条消息,然后它让每个人都知道它正在更新并且会有停机时间?如果有人知道帮助,请告诉我!
解决方案
您可以通过检查您的机器人所在的每个服务器是否有一个名为“公告”的频道,然后向该频道发送消息来实现这一点。
这假设您的机器人已在名为 的变量下初始化client
。
// Set our message. This can also be an Attachment or RichEmbed
var message = "Going offline due to updates! Be back in 10 minutes.";
// For all the servers this bot is in,
client.guilds.forEach((guild) => {
// Look for a channel named "announcements".
var channel = guild.channels.find(channel => channel.name === "announcements");
// Make sure that "channel" is not null (i.e. it exists)
if (channel !== null)
// Send our update message.
channel.sendMessage(message);
});
请注意,如果您的机器人是公开的并且位于您无法控制的其他服务器上,则不建议这样做,因为它完全是无端的,并且可能会激怒某些服务器所有者。
推荐阅读
- firebase - Flutter App 的 Firestore 模拟器 UI 中未显示数据
- c# - 如何将空字符串反序列化为所有`Nullable的空值
` 使用 System.Text.Json 的值类型? - r - 如何将 3 小时的 TRMM 降雨数据汇总为每日值?
- hana - 带有表变量的 SQL 视图
- json - 如何使用 Postman 中 json 文件中的时间戳字段对 json 进行排序?
- c - 在 C 中使用重定向进行文件输入?
- yocto - 是否可以将其他开发包“安装”到 SDK 中
- swift - 使用全局数组更新滚动视图
- image - 使用面部标志的情绪检测
- arrays - 将结构数组作为函数的参数传递