【问题标题】:discord.js How to revoke a ban of a banned user using code?discord.js 如何使用代码撤销对被禁止用户的禁令?
【发布时间】:2021-03-12 01:28:33
【问题描述】:

使用代码撤销禁令

所以,我正在使用 VS Code 制作一个审核不和谐机器人,并且我已经设置了一个禁止命令。我也想发出一个解禁命令(撤销禁令),这样用户就可以轻松地解禁用户而不必进入Server Settings 来执行此操作。

我知道你可以做到,因为我一直在使用另一个机器人 GAwesomeBot,它能够做到。
GAwesomeBot 链接:https://gawesomebot.com

我对 Stack Overflow 有点陌生,这是我的第一个问题,如果我做错了什么,请原谅我。

【问题讨论】:

    标签: javascript visual-studio-code discord.js


    【解决方案1】:

    考虑使用 GuildMemberManager#unban https://discord.js.org/#/docs/main/stable/class/GuildMemberManager?scrollTo=unban

    let guildMemberManager, toUnbanSnowflake;
    guildMemberManager.unban(toUnbanSnowflake); // Takes UserResolveable as argument
    

    【讨论】:

    • 哦,嗯,我想你误会了,我正在尝试在他/她被禁止后解禁公会中的用户。
    【解决方案2】:

    首先,您要定义要解禁的用户。
    由于该用户已被禁止,您必须通过其 ID 提及该用户,然后取消禁止该用户。

    let args = message.content.split(/ +/g); //Split the message by every space
    let user = message.guild.members.cache.get(args[1]); //getting the user
    user.unban({ reason: args[2].length > 0 ? args[2] : 'No reason provided.' }); //Unbanning the user
    

    完整示例:

    //Define your variables
    const Discord = require('discord.js');
    const client = new Discord.Client();
    var prefix = 'your-prefix-here';
    
    //Add a message event listener
    client.on('message', () => {
        let args = message.content.split(/ +/g); //Split the message by every space
        if (message.content.toLowerCase() === prefix + 'unban') {
            let user = message.guild.members.cache.get(args[1]); //getting the user
            if (!user) return message.channel.send('Please specify a user ID');
            user.unban({ reason: args[2].length > 0 ? args[2] : 'No reason provided.' }).then(() => message.channel.send('Success');
        }
    });
    

    【讨论】:

    • 当您声明 let user = ... 时,我似乎无法获取用户,它返回未定义。我认为这是因为用户被禁止并且不再在服务器中。也许我错了,请帮助!我在这里真的很新。
    • 您需要获取用户ID才能解禁他们。如果你的前缀是!,你会在你的 Discord 公会中说!unban 123456789 123456789 代表用户的ID,你可以通过右键单击用户并选择选项copy ID 来获得它。但是,您必须在设置中启用 Discord Developer Mode
    • 感谢您的帮助!解决了我的问题!
    猜你喜欢
    • 2021-01-11
    • 2021-06-01
    • 2021-09-05
    • 2021-07-27
    • 2022-11-06
    • 2020-11-18
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多