【发布时间】:2019-08-07 13:48:03
【问题描述】:
我想让我的机器人能够创建一个由命令触发的 webhook,然后 webhook 可以说出一段间隔的消息。 我想获取已创建的 webhook 的令牌和 id,然后将其放在一个持续不断的 setInterval 上,直到 webhook 被删除。
const Discord = require('discord.js');
const commando = require('discord.js-commando');
class pingy extends commando.Command
{
constructor(client) {
super(client, {
name: 'pinghook',
group: 'help',
memberName: 'pinghook',
description: 'git',
})
}
async run(message, args){
var args = Array.prototype.slice.call(arguments);
const nameAvatar = args.join(" ");
const linkCheck = /https?:\/\/.+\.(?:png|jpg|jpeg)/gi;
if (!linkCheck.test(nameAvatar)) return message.reply("You must supply an image link.");
const avatar = nameAvatar.match(linkCheck)[0];
const name = nameAvatar.replace(linkCheck, "");
const name2 = "PingBot";
message.channel.createWebhook(name, avatar)
.then(webhook => webhook.edit(name2, avatar)
.catch(error => console.log(error)))
.then(wb => hook
.catch(error => console.log(error)))
.catch(error => console.log(error));
const hook = new Discord.WebhookClient(wb.id, wb.token)
setInterval(() => {
hook.send("@everyone you've been pinged.")
}, 1500);
}};
module.exports = pingy;
这是我在尝试编写此代码时遇到的一些错误。 ReferenceError: wb is not defined
我的期望:我的机器人可以创建一个由用户激活的 webhook,然后 webhook 会每隔一段时间发送一条消息,直到被删除。从最近创建的 webhook 中获取 webhook.id 和 webhook.token 来执行此操作。
现实: ReferenceError: wb is not defined
【问题讨论】:
标签: javascript node.js webhooks discord.js