-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (35 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { Client, EmbedBuilder, GatewayIntentBits } = require('discord.js');
class WebhookSender {
constructor(channelId, token, embed) {
this.channelId = channelId;
this.client = new Client({ intents: [GatewayIntentBits.Guilds] });
this.embed = embed || new EmbedBuilder();
this.token = token;
}
async send(content, username, avatarURL) {
try {
await this.client.login(this.token);
const channel = await this.client.channels.fetch(this.channelId);
const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.find(wh => wh.token);
if (!webhook) {
console.log('No webhook was found that I can use!');
return;
}
await webhook.send({
content,
username,
avatarURL,
embeds: [this.embed],
});
} catch (error) {
console.error('Error trying to send a message: ', error);
} finally {
await this.client.destroy();
}
}
}
// Exemplo de uso:
// const webhookSender = new WebhookSender('', "");
// webhookSender.send('Webhook test', 'some-username', '');
export default WebhookSender;