简体   繁体   English

如何使用discord.js v12登录discord的ban部分?

[英]How to log into the ban section of discord using discord.js v12?

I'm working on my ban command and it's fully functional, but I was wondering, how I would log the ban reason into the ban section of discord (example in the attachment)?我正在处理我的禁令命令并且它功能齐全,但我想知道如何将禁令原因记录到不和谐的禁令部分(附件中的示例)? My code looks like this:我的代码如下所示:

const { DiscordAPIError } = require("discord.js");
const Discord = require('discord.js');

module.exports = {
    name: 'ban',
    description: "Mentioned user will be banned",
    execute(message, args){
        if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("Invalid Permissions")
        let User = message.guild.member(message.mentions.members.first()) || message.guild.members.cache.get(args[0])
        if (!User) return message.channel.send("Invalid User")
        if (User.hasPermission("BAN_MEMBERS")) return message.reply("Invalid Permissions a")
        let banReason = args.join(" ").slice(22);
        if (!banReason) {
            banReason = "None"
        }
        console.log(`USER = ${User}`)
        User.ban
        console.log(`Ban reason = ${banReason}`)
        var UserID = User.id
        console.log(`USER ID = ${UserID}`)
    }
}

Any help?有什么帮助吗? Thanks :)谢谢 :)

在此处输入图片说明

It's actually quite easy, just add ({reason: banReason}) after the User.ban part, making it:其实很简单,只需在User.ban部分后添加({reason: banReason}) ,就可以了:

User.ban({reason: banReason})

That should log it there properly :)那应该正确地将其记录在那里:)

You can use the reason property of the options parameter in the GuildMember.ban() method:您可以在GuildMember.ban()方法中使用options参数的reason属性:

User.ban({ reason: 'real life danger' })
  .then(member => console.log(`${member.name} was banned.`))
  .catch(console.error)

Also, in your code, there's no reason for using the Guild.member() method when defining User .此外,在您的代码中,在定义User时没有理由使用Guild.member()方法。 Guild.member(user) is used to turn a User object into a GuildMember object. Guild.member(user)用于将User对象转换为GuildMember对象。

However,MessageMentions.members.first() already returns a GuildMember object, making it obsolete.但是,MessageMentions.members.first()已经返回GuildMember对象,使其过时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM