gpt4 book ai didi

discord.js - 如何检查机器人是否有权管理 webhook?

转载 作者:行者123 更新时间:2023-12-04 10:19:35 24 4
gpt4 key购买 nike

My problem is that I'm getting an error whenever I use the following code:


else if (cmd === "sayw") {
const embed2 = new Discord.RichEmbed()
.setDescription("❌ You can't make me say nothing! \nWait, you just did-")
.setFooter(`Requsted by ${message.author.tag}.`, message.author.avatarURL)
if(!args[0]) return message.channel.send(embed2)
const guild = message.guild
const embed = new Discord.RichEmbed()
.setAuthor("Say Webhook", bot.user.avatarURL)
.setDescription("❌ I need the `MANAGE_WEBHOOKS` permision first!" )
.setImage(`https://i.gyazo.com/d1d5dc57aa1dd20d38a22b2f0d4bd2f6.png`)
const member = guild.members.get(bot.id)
if (member.hasPermission("MANAGE_WEBHOOKS")) {
message.channel.createWebhook(message.author.username, message.author.avatarURL)
.then(webhook => webhook.edit(message.author.username, message.author.avatarURL))
.then(wb => {wb.send(args.join(" "))
setTimeout(() => {
bot.fetchWebhook(wb.id, wb.token)
.then(webhook => {
console.log("deleted!")
webhook.delete("Deleted!")
}, 5000)})})
} else {
message.channel.send(embed)
}}


I want the bot to tell the user if it can't create the webhook, but instead, I get this error when trying to use this command: (node:10044) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'hasPermission' of undefined



我如何使此代码工作?

最佳答案

如果您使用的是 Discord.js v12(最新版本),guild.members.get(bot.id)不能用作 guild.memebrs现在是 GuildMemberManager .



const member = guild.members.cache.get(bot.id)

或者您甚至可以将其用作快捷方式:

const member = guild.me

关于discord.js - 如何检查机器人是否有权管理 webhook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60921773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com