Skip to content

Commit

Permalink
feat(webhooks): only find executable webhooks (discordjs#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
KK-Designs authored Dec 14, 2021
1 parent ecd614f commit 8ca8c74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion code-samples/popular-topics/webhooks/13/using-Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ client.once('ready', async () => {
const channel = client.channels.get('222197033908436994');
try {
const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.first();
const webhook = webhooks.find(wh => wh.token);

if (!webhook) {
return console.log('No webhook was found that I can use!');
}

await webhook.send({
content: 'Webhook test',
Expand Down
8 changes: 6 additions & 2 deletions guide/popular-topics/webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ webhookClient.send({
});
```

Example using a Webhook:
Try to find a webhook your bot knows the token for. This makes sure your bot can execute the webhook later on.

```js
const { Client, Intents, MessageEmbed } = require('discord.js');
Expand All @@ -141,7 +141,11 @@ client.once('ready', async () => {
const channel = client.channels.cache.get('123456789012345678');
try {
const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.first();
const webhook = webhooks.find(wh => wh.token);

if (!webhook) {
return console.log('No webhook was found that I can use!');
}

await webhook.send({
content: 'Webhook test',
Expand Down

0 comments on commit 8ca8c74

Please sign in to comment.