Discord.js机器人将消息发送到其所在的每个服务器中的特定通道

到目前为止,我已经知道了:

function dailylot(){
    let channel = message.guild.channels.find(channel => channel.name === "general69420")
    if(!channel){return;}
    channel.send(".")
    return;
}
function settimer(){
    setTimeout(() => {
        settimer()
        dailylot()
        console.log("Cycle")
    },5000)
}
while (i < 1){
    console.log("set timer " + i);
    settimer()
    i++;
}

此操作有效,但仅对发送邮件的服务器有效。即使删除了While,因此它多次激活,也只想转到一台服务器。如何检索所有服务器的通道? bot.guilds.channels不是问题。

julia_cm 回答:Discord.js机器人将消息发送到其所在的每个服务器中的特定通道

您需要遍历机器人中的每个公会并获取每个tem的通道,之所以如此,是因为与messageguild不同,guilds是不是类,这意味着它不具有guilds.channels之类的属性,它是其他行会类的集合。

这是有关如何单独访问这些频道的示例:

client.guilds.forEach(guild => {
    guild.channels.forEach(channel => {
        // Use the channel for whatever you need
    })
})
本文链接:https://www.f2er.com/3139556.html

大家都在问