javascript - 解禁 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 数组。
解决方案
没有必要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);
}
确保在必要时使用分号——这样可以避免以后出现恼人的错误
推荐阅读
- php - Laravel 为外部用户登录成功设置会话或令牌 - 无用户仅数据库 Api 用户
- python - 如何将信息获取到数据框?
- java - Elasticsearch:java.lang.IllegalArgumentException:在 docker 容器上运行时不允许自我抑制
- c++ - 为什么我的后增量运算符重载在 cout 流中不起作用?
- php - Symfony LexikMaintenanceBundle - 服务“lexik_maintenance.driver.factory”依赖于不存在的服务“translator.default”
- python - Django Admin 如何添加过滤器菜单,如基本 UserModel:
- angular - 角模板冻结直到操作完成
- postgresql - 如何在逗号后使用 3 个数字将 varchar 转换为浮点类型 PostgreSQL
- android - 在 Android 8.0 (Oreo) 中打开几秒钟后热点会自动关闭
- javascript - 过滤器/搜索 - 删除搜索前查看可搜索项目的选项