擁有這個斜杠命令代碼并將其轉換為 webhook。當我使用它一次時它起作用了,但在那之后它就停止了作業。我得到了這個錯誤DiscordAPIError: Maximum number of webhooks reached (10)。有誰知道如何解決這個問題?
代碼:
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]})
})
}
}
uj5u.com熱心網友回復:
您無法修復該錯誤,discord 會限制每個通道的 webhook(每個通道 10 個 webhook)。
但是,如果您不希望代碼回傳錯誤,您可以將該代碼放入 atry catch或添加.catch
以下是如何處理錯誤的示例:
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
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/430857.html
