繁体   English   中英

如何修复权限系统中的错误? (DISCORD.JS)

[英]How do I fix the error in my permission system? (DISCORD.JS)

错误:

(node:6468) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'roles' of null
    at Object.module.exports.run (C:\Users\Pc\Desktop\Anuncios\comandos\vote.js:5:24)
    at C:\Users\Pc\Desktop\Anuncios\bot.js:141:57
    at C:\Users\Pc\Desktop\Anuncios\node_modules\mongoose\lib\model.js:4845:16
    at C:\Users\Pc\Desktop\Anuncios\node_modules\mongoose\lib\query.js:4283:12
    at C:\Users\Pc\Desktop\Anuncios\node_modules\mongoose\lib\query.js:2776:28
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
(node:6468) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

代码:

const discord = require('discord.js')

module.exports.run = async (bot, message, args) =>{
    message.delete()
    if(!message.member.roles.some(r=> ["❪⚡❱❱❱Founder★★★★"].includes(r.name)) ) {
        return message.reply(` você não tem permissão de fazer isso!`)
    }
    let mensagem = args.join(' ')
    if(!args[0]) {
        return message.reply(`<:prohibited:814861316715839488> você não adicionou algo para ser avisado!`)
    }
    var embed = new discord.RichEmbed()
    .setColor("RANDOM")
    .setAuthor('SERVER - VOTAÇÃO', bot.user.avatarURL)
    .setDescription(mensagem)
    .setFooter(message.author.username, message.author.avatarURL)
    .setTimestamp()
    .setThumbnail(bot.user.avatarURL)
    bot.guilds.get('771513497069682711').channels.get(`786364363133026336`).send('@everyone').then(m =>{
    m.delete(100)
    })
    bot.guilds.get(`771513497069682711`).channels.get(`786364363133026336`).send(embed)
}

module.exports.config = {
    name: 'vote',
    aliases: ['votar', 'qcv']
}

我也尝试切换到权限验证方法,但是,它会产生另一个错误,我总是使用这种方法进行权限验证,不知道为什么会出现此错误,有人可以帮助我吗?

从 discord.js v12 开始,您可以参考message.member.roles.cache

await message.delete();

if (!message.member.roles.cache.some(r => ['❪⚡❱❱❱Founder★★★★'].includes(r.name))) {
  return message.reply(` você não tem permissão de fazer isso!`);
}

由于这不是一个缩小或可重现的示例,因此没有太多方法可以完全测试它。

你有什么导致这些命令的例子吗?

令我困惑的是,您稍后尝试回复此消息。 之前,您似乎通过不同步删除来创建竞争条件,但我可能会建议在消息的上下文不再相关或根本不删除时有条件地删除消息。

另外,请注意,当您删除消息时,您将超时传递给 object,而不是 integer:

await message.delete({ timeout })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM