取消禁止 id 数组 discord.js v12

时间:2021-03-01 15:02:54

标签: javascript node.js discord discord.js

代码:

if (command === "ubm") {
    console.log(chalk.yellow`You ran a command: ubm`);
    const guild = client.guilds.cache.get(args[0]);
    const me = config.ownerID;
    await guild.fetchBans(me).then((g) => {
        g.members.unban(me);
    });
}

错误:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'fetchBans' of undefined

有人知道这是怎么回事吗?命令如下所示:

-ubm <服务器 ID>

请注意,config.ownerID 是一个 ID 数组。

1 个答案:

答案 0 :(得分:0)

无需fetch禁止您的服务器。只需使用 message.guild.members.unban(id)

示例:

if(command === "ubm"){
    console.log((chalk.yellow)`You ran a command: ubm`);
    const guild = client.guilds.cache.get(args[0]); //I would suggest adding some error trapping here, as if the guild doesnt exist the bot will throw
    const me = config.ownerID[0]; //get necessary element in array
    message.guild.members.unban(me); 
}

确保在必要时使用分号 - 这样可以避免以后出现烦人的错误