Home > Software design >  Discord.js maximum number of webhooks error
Discord.js maximum number of webhooks error

Time:02-22

Have this slash command code and turned it into webhook. It worked when I used it once but it stopped working after that. I got this error DiscordAPIError: Maximum number of webhooks reached (10). Does anyone have any idea on how to fix this?

Code:

    run: async (client, interaction, args) => {

      if(!interaction.member.permissions.has('MANAGE_CHANNELS')) {
        return interaction.followUp({content: 'You don\'t have the required permission!', ephemeral: true})
      }
      
        const [subcommand] = args;

  const embedevent = new MessageEmbed()

        if(subcommand === 'create'){
        
            const eventname = args[1]

            const prize = args[2]

            const sponsor = args[3]
            
            embedevent.setDescription(`__**Event**__ <a:w_right_arrow:945334672987127869> ${eventname}\n__**Prize**__ <a:w_right_arrow:945334672987127869> ${prize}\n__**Donor**__ <a:w_right_arrow:945334672987127869> ${sponsor}`)
            embedevent.setFooter(`${interaction.guild.name}`, `${interaction.guild.iconURL({ format: 'png', dynamic: true })}`)
            embedevent.setTimestamp()

        }
        
        await interaction.followUp({content: `Event started!`}).then(msg => {
    setTimeout(() => {
  msg.delete()
}, 5000)    
  })    

        interaction.channel.createWebhook(interaction.user.username, {
     avatar: interaction.user.displayAvatarURL({dynamic: true})
 }).then(webhook => {    
webhook.send({content: `<@&821578337075200000>`, embeds: [embedevent]})
  })

    }
}

CodePudding user response:

You cannot fix that error, discord limits webhooks per channel (10 webhooks per channel).

However, if you don't want your code to return an error you can just chock that code into a try catch or add a .catch

Here is an example of how to handle the error:

try {
    interaction.channel.createWebhook(interaction.user.username, {
        avatar: interaction.user.displayAvatarURL({dynamic: true})
    }).then(webhook => {    
        webhook.send({content: `<@&821578337075200000>`, embeds: [embedevent]})
    })
} catch(e) {
    return // do here something if there is an error
}
  • Related