我需要一些代码来允许我在我的机器人所在的服务器之间发送网络钩子。
就像机器人“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)
}
}
答案 0 :(得分:0)
我认为您的错误要么来自错误的 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(" "))
}
}