如何为discord.js机器人发出ban命令?

时间:2020-08-06 04:19:48

标签: javascript discord discord.js

const Discord = require('discord.js');
const config = require('../config.json');
const log = require(`leekslazylogger`);
module.exports = {
  name: 'ban',
  description: 'This is for admins only',
  usage: '',
  aliases: ['Ban'],
  example: '',
  args: false,
  cooldown: config.cooldown,
  guildOnly: true,
  execute(message, args) {
    const client = message.client;
    // command starts here
    message.delete();

到目前为止,这就是我所拥有的。我没有发出禁止命令的方法,但我尝试过发出禁止命令,但是每次执行该命令时,机器人启动时都会遇到很多错误。有人知道该怎么做吗?

1 个答案:

答案 0 :(得分:0)

我会给你一些你可以编辑的代码以避免“克隆”。

如果您愿意,您可以对其进行编辑以进行嵌入 这是它:

if (!message.member.hasPermission('BAN_MEMBERS'))
  return message.channel.send(
    "You can't use that!\nYou need the 'Ban Members' permission"
  );
let member = message.mentions.members.first();
let reason = args.slice(1).join(' ');
if (!member) {
  message.delete();
  message.channel.send('You need mention someone!');
} else {
  message.delete();
  message.channel.send(
    '<@' + member + '> Has been successfully banned from the guild'
  );
  member.ban(member, reason);
  console.log(`Banned someone on:\n ${message.guild.name} `);
}