TOOLBOX Course

Webhook

Go back

A webhook is something like this. It's a bot taking someone else avatar/name and posting a message in a channel.

webhook


Using discohook, you can create your webhook online (or learn how a webhook is made), then in JavaScript

// fetch channel webhooks
const webhooks = await channel.fetchWebhooks();
let hook = webhooks.first();
// check if there isn't an existing webhook
if (hook === undefined) {
    //creates
    await channel.createWebhook(
        // avatar is the url to an avatar
        Config.hook_name, {avatar: avatar})
        .then(webhook => { hook = webhook; })
        .catch(console.error);
}

// 
// params is the JSON you generated with discohook
// for instance
// let params = {username: name, avatarURL: avatar, content: message};
//
await hook.send(params);

Here the bot will create a webhook (if there isn't already one) for the channel, then it will send a message using the webhook. These created webhooks are in Integrations > [Your bot name] and not in the Webhook menu.

You may check out https://birdie0.github.io/discord-webhooks-guide/ for a fully explained guide.