A Guide to Discord Bots

Webhooks

Webhooks are a really cool feature of Discord; you can post messages and embeds with a POST request.
The name and avatar of the bot can be changed to your liking for each message.

This can be useful to automatically redirect Twitter messages to your server or new YouTube videos to a certain channel.
There are websites available for this, such as Zapier.

Creating a Webhook

Go to your server's settings, then click "Webhooks" and "Create Webhook".
Give it any name and icon you want, choose the channel which will contains your messages.
Copy the URL and save.
Note: don't share the webhook URL, or anyone would be able to send anything in the selected channel.

Sending to your Webhook

// https://discordapp.com/api/webhooks/ID/Token
const myHook = new Discord.WebhookClient('ID', 'Token');

// Sending a normal message
myHook.send('Hello World!');
myHook.send('Hello World!').then(message => console.log('Sent: ' + message.content));

// Sending images
myHook.send({
  files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png']
});

webhook.send({
  files: [{
    attachment: 'file.jpg',
    name: 'file.jpg'
  }]
});

// Sending embeds
myHook.send({
    embeds:
        [{
            'title': '**Hey!**',
            'description': 'Testing webhooks _with embeds_',
            'color': 0,
            'fields': [
                {
                    'name': 'Webhooks',
                    'value': 'They just _work_.'
                }
            ]
        }]
});

You can also find the examples here: WebhookClient.
You can manually send requests to your Webhook with DisHook.

results matching ""

    No results matching ""