首页 > 解决方案 > 解禁 id 数组 discord.js v12

问题描述

代码:

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 数组。

标签: javascriptnode.jsdiscorddiscord.js

解决方案


没有必要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); 
}

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


推荐阅读