简体   繁体   中英

unban array of ids discord.js v12

Code:

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);
    });
}

Error:

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

Does anyone know what's wrong with this? The command looks like this:

-ubm <Server ID>

Note that config.ownerID is an Array of IDs.

There is no need to fetch the bans of your server. Simply use a message.guild.members.unban(id)

Example:

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); 
}

Make sure you use semicolons where necessary - it saves irritating errors later

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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