【问题标题】:Discord.js How would I create a bot status announcement?Discord.js 如何创建机器人状态公告?
【发布时间】:2021-04-25 12:27:15
【问题描述】:

我需要一些代码来允许我在我的机器人所在的服务器之间发送一个 webhook。

就像“Dank Memer”机器人如何将网络钩子发送到它所在的服务器一样,了解机器人的状态。

例如:

“Dank Memer 官方 #bot-status SERVER 01/18/2021 我们正在等待我们的主人关于这个问题的回复。大多数机器人都在线,但表现不佳。

我建议在解决此问题之前不要使用它,这种延迟可能会出现奇怪的错误。”

当我查看 discord 服务器时,所有人所做的就是在频道中发送一条消息,然后它在特定频道中的整个服务器中发送该消息。

我只有:

module.exports = {
name: 'announce',
description: 'Sends a webhook annoucment to the channel that I specify',
execute(client, message, args, Discord) {
    const webhookClient = new Discord.WebhookClient('ID', 'Token');
    
    var announcement = "";
    for (const word in args) {
        announcement = announcement + args[word] + " ";
    }
    webhookClient.send(announcement)
}

}

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    我认为您的错误来自错误的 webhook 或错误的参数选择。 这段代码应该可以工作,如果不行,请告诉我!

    module.exports = {
        name: 'announce',
        description: 'Sends a webhook annoucment to the channel that I specify',
        execute(client, message, args, Discord) {
            const webhookChannelID = "Put your channel ID here";
            const channel = message.guild.channels.cache.get(webhookChannelID)
    
            const webhooks = await channel.fetchWebhooks();
            const webhook = null;
            if(webhooks.array().length == 0){
                webhook = await channel.createWebhook('Example Webhook');
            }
            else{
                webhook = webhooks.first();
            }
            webhook.send(args.join(" "))
        }
    }
    

    【讨论】:

    • 我有一个新的 (node:12972) UnhandledPromiseRejectionWarning: TypeError: webhook.send is not a function
    • 我怎样才能发送到多个频道,所有不同的服务器?
    • 创建一个包含 execute() 内容的方法,然后为您需要的每个频道 ID 调用它 ^
    猜你喜欢
    • 2022-01-07
    • 2021-07-30
    • 2022-11-11
    • 2021-01-11
    • 2020-01-22
    • 2021-05-07
    • 2018-07-28
    • 2020-05-30
    • 2023-04-10
    相关资源
    最近更新 更多