Greyson Phipps
Greyson Phipps

Reputation: 45

How can I delete a webhook in discord.js?

I want to create a &imitate [user] [sentence] command in discord.js, and I want to delete the webhook when it's finished with the command. I have this code:

message.channel.createWebhook("Webhook Test", "https://images.app.goo.gl/2rvCG9hndnTYbQqU9")
.then(webhook => webhook.edit({channel: message.channel})
.then(wbhk => wbhk.send('Testing message'))
.then(wb => wb./*What do I put here to delete the webhook?*/).catch(console.error)

I was looking around for hours and couldn't find anything about this except for the discord.js docs.

Upvotes: 1

Views: 926

Answers (2)

Mapahce2212
Mapahce2212

Reputation: 1

To delete a Webhook you can use that:

 let webno = message.channel.createWebhook({
        name: "Test",
        avatar: "https://www.example.com/image23125.png"
    });

    webno.send({
        content: "text here"
    })

    function waiti() {
        webno.delete()
    }
    setTimeout(waiti, 2000)

This is much better than using then because errors can occur working with this element. This code is simple.

Upvotes: 0

theusaf
theusaf

Reputation: 1802

To delete a Webhook, you would use Webhook.delete():

message.channel.createWebhook("Webhook Test", "https://images.app.goo.gl/2rvCG9hndnTYbQqU9")
  .then(webhook => webhook.edit({channel: message.channel})
  .then(webhook => {
    return webhook.send('Testing message').then(message => webhook); // returns the webhook, rather than the message to the next .then call
  })
  .then(webhook => webhook.delete()).catch(console.error)

Upvotes: 3

Related Questions