Discord.js 如何检查bot是否有permmsion来管理webhook?
我的问题是,每当我使用以下代码时,都会出现错误: 我希望bot告诉用户它是否无法创建webhook,但是,当尝试使用此命令时,我会出现以下错误:Discord.js 如何检查bot是否有permmsion来管理webhook?,discord.js,Discord.js,我的问题是,每当我使用以下代码时,都会出现错误: 我希望bot告诉用户它是否无法创建webhook,但是,当尝试使用此命令时,我会出现以下错误: (节点:10044)未处理的PromisejectionWarning:TypeError:无法读取未定义的属性“hasPermission” 如何使用此代码?如果您使用的是Discord.js v12(最新版本),guild.members.get(bot.id)将无法作为guild.memebrs工作 使用 const member=guild.m
(节点:10044)未处理的PromisejectionWarning:TypeError:无法读取未定义的属性“hasPermission”
如何使用此代码?如果您使用的是Discord.js v12(最新版本),
guild.members.get(bot.id)
将无法作为guild.memebrs
工作
使用
const member=guild.members.cache.get(bot.id)
或者您甚至可以将此用作快捷方式:
const member=guild.me
谢谢!我使用12点之前的最新版本。但我相信这对我来说仍然很有效!
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)
}}