我的ban命令在权限管理器中给出错误



由于某些原因,我的ban命令中的权限行不起作用。下面是我在尝试运行bot时得到的错误:

if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) {return message.channel.send(
^
SyntaxError: Unexpected token '!'

这也是我的ban命令:

const { MessageEmbed, Message } = require('discord.js');
const fs = require('fs');
const os = require('os');
const config = require('../config.json');
const CatLoggr = require('cat-loggr');
// Functions
const log = new CatLoggr();
module.exports = {
name: 'ban', // Command name (can be different from the file name)
description: 'Bans a member.', // Command description displays in the help command
if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) {return message.channel.send(
new MessageEmbed()
.setColor(config.color.red)
.setTitle('Error occurred!')
.setDescription('You do not have permission to use this command!')
.setFooter(message.author.tag, message.author.displayAvatarURL({ dynamic: true, size: 64 }))
.setTimestamp()
)
};
//get first mentioned member
const member = message.mentions.users.first()
if (!member) return message.channel.send(
new MessageEmbed()
.setColor(config.color.red)
.setTitle('Missing parameters!')
.setDescription('Please mention the member you want to ban!')
.setFooter(message.author.tag, message.author.displayAvatarURL({ dynamic: true, size: 64 }))
.setTimestamp()
)
//Convert member to a user so we can use it
const user = message.guild.member(member)
try {
//Ban user
user.ban()
message.channel.send(
new MessageEmbed()
.setColor(config.color.red)
.setTitle('Member Banned!')
.setDescription(``${member.username} has been banned!`)
.setFooter(message.author.tag, message.author.displayAvatarURL({ dynamic: true, size: 64 }))
.setTimestamp()
)

} catch (err) {
console.log(err)
return message.channel.send(
new MessageEmbed()
.setColor(config.color.red)
.setTitle('Error occurred!')
.setDescription(`Couldn't ban `${member.username}` make sure I have the right roles!`)
.setFooter(message.author.tag, message.author.displayAvatarURL({ dynamic: true, size: 64 }))
.setTimestamp()
)

我试着重写代码,也删除和添加一些部分,但仍然不工作。如果你能帮我解决这个问题,我将不胜感激,谢谢。

您正在传递正常的JS代码而不是变量到module.exports。你必须把它放在其他地方,就像一个在命令执行时运行的函数。

您忘记了async execute(message)我认为这段代码可以工作。

const { MessageEmbed, Message } = require('discord.js');
const fs = require('fs');
const os = require('os');
const config = require('../config.json');
const CatLoggr = require('cat-loggr');

// Functions
const log = new CatLoggr();

module.exports = {
name: 'ban', // Command name (can be different from the file name)
description: 'Bans a member.', // Command description displays in the help command

async execute(message){ 
if(!message.guild.member(message.author).hasPermission("ADMINISTRATOR")) {return message.channel.send(..........

相关内容

最新更新