【发布时间】:2018-06-27 00:13:33
【问题描述】:
目前我正在开发一个事件机器人,该机器人用于 Discord 中的几个小组。 所以现在我有这个代码:
if (command === "init")
{
//var d = new Date();
//var n = d.getHours();
message.channel.send("BunnBot starting...");
var interval = setInterval (function () {
message.channel.send("123")
//message.channel.send(n);
}, 30 * 1000);
}
问题是,该命令仅适用于当前组,这意味着在任何其他组中我也必须使用 init 命令。
我该如何解决?如何让我的 Bot 向每个群组发送消息?
编辑: 好的,我稍微更改了代码,现在我正在使用它: 好的,这是我的新代码,现在我遇到了一条错误消息,即发送不是函数
client.on("ready", () => {
console.log('Logged in as BunnyBot');
setInterval (function () {
client.guilds.forEach(() => { //for each guild the bot is in
let defaultChannel = "";
client.guilds.forEach((channel) => {
if(channel.type == "text" && defaultChannel == "") {
if(channel.permissionsFor(guild.me).has("SEND_MESSAGES")) {
defaultChannel = channel;
}
}
})
message.defaultChannel.send("Message here"); //send it to whatever channel the bot has permissions to send on
console.log("Sending Messages");
})
}, 1 * 1000);
})
问题:现在我收到一条错误消息,即 send 不是函数。
【问题讨论】:
-
按组是指
guild还是server? -
有区别吗?有人告诉我,每个 Discord-Group 都称为公会。有人称它为服务器,对吧?
-
@Xanar 你把它们命名为公会和服务器是正确的(至少不和谐)。你的问题中没有澄清的一点是你的消息应该发送到公会的哪个频道?否则,它非常简单。
-
通常我希望消息在#general-channel 中。问题是,Discord 不再有默认房间,所以#general-channel 可能被称为 #the-lounge 左右。
标签: javascript discord discord.js