首页 > 解决方案 > Discord权限检查不起作用dsicord js

问题描述

出于某种原因,当我尝试使用我的命令时,它一直给我这个错误。下面列出了错误和代码。我尝试修复它似乎没有修复它

const Discord = require("discord.js");

module.exports = {
    name: 'clear',
    aliases: ['purge'],
    discription: "clears messages",
    async execute(message, args, client) {
        if (!message.member.hasPermission('MANAGE_MESSAGES')) return message.reply('You do not have permissions to use this command')
        if (!args[0]) return message.reply(`Please specify a amount of messages to delete (1-99)`)
        if (isNaN(args[0])) return message.reply(`Please enter a number`)
        if (parseInt(args[0]) > 99) return message.reply(` The max amount of messages you may delete is 99`)

        await message.channel.bulkDelete(parseInt(args[0]) + 1)
            .catch(err => console.log(err))
        message.channel.send(`deleted ${args[0]} messages`).then(m => m.delete({ timeout: 5000 }))
    }
}
PS C:\Users\lolzy\OneDrive\Desktop\discordbot> node .
Cbs slave is online!
(node:10108) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'hasPermission' of undefined

标签: discorddiscord.js

解决方案


尝试这个:

const Discord = require("discord.js");

module.exports = {
    name: 'clear',
    aliases: ['purge'],
    discription: "clears messages",
    async execute(client, message, args) {
        if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel,send('You do not have permissions to use this command')
        if (!args[0]) return message.reply(`Please specify a amount of messages to delete (1-99)`)
        if (isNaN(args[0])) return message.reply(`Please enter a number`)
        if (parseInt(args[0]) > 99) return message.reply(` The max amount of messages you may delete is 99`)

        await message.channel.bulkDelete(parseInt(args[0]) + 1)
            .catch(err => console.log(err))
        message.channel.send(`deleted ${args[0]} messages`).then(m => m.delete({ timeout: 5000 }))
    }
}

推荐阅读