Reputation: 59
Error:
(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)
Code:
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']
}
I also tried to switch to a permission verification method, however, it generates another error and I always used this method for permission verification and do not know why it is giving this error, can anyone help me?
Upvotes: 1
Views: 99
Reputation: 786
As of discord.js v12, you would refer to message.member.roles.cache
instead.
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!`);
}
As this isn't a minified or reproducible example, there's not much of a way to fully test this.
Do you have an example of what incurs these commands?
What confuses me is that you later try to reply to this message. Prior, it seems that you created a race condition by not deleting synchronously, but I might suggest conditionally delete the message once its context is no longer relevant or not delete at all.
Also, note that when you are deleting messages, you pass a timeout to an object, not an integer:
await message.delete({ timeout })
Upvotes: 1