discord - 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
解决方案
尝试这个:
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 }))
}
}
推荐阅读
- python - 任何 Jenkins API 中是否有一个函数可以为我提供从节点 COMPUTERNAME/Hostname
- javascript - 错误时打破承诺链执行[重复]
- mysql - Node.js 和 mysql 公告板搜索功能题
- vue.js - 使用 axios 或 vue-resource 的 VueJS 的 CORS 问题
- amazon-web-services - 我没有从 dynamoDB 得到任何答案
- python - Turtle 在 jupyter notebook 中不会多次运行
- sql - 来自 2 个表的具有相同记录数的不相交集
- compiler-errors - 使用 Cray Fortran 编译器 (cce 8.7.9) 轻松实现整数和逻辑之间的隐式类型转换
- actions-on-google - 如何让我的智能家居操作在我的设备上可用?
- java - Springboot 读取我的 yml 但即使我传入值也是 null