javascript - 如何制作不和谐机器人以在其他公会中创建邀请
问题描述
我无法让机器人向该机器人所在的另一个公会发出邀请。
我尝试为我的机器人赋予管理员角色以确保它具有权限。
if(msg.content.startsWith('-createinvite')) {
const args = msg.content.split(' ').slice(1)
if(!args[0])
var invitechannels = guild.channels.filter(c => c.members.get(bot.user.id).hasPermission("CREATE_INSTANT_INVITE")).first();
var guild = client.guilds.get(args[0]);
if (!guild) return msg.reply("The bot isn't in the guild with this ID.");
if(!invitechannels) return msg.channel.send('No Channels found with permissions to create Invite in!')
console.log(invitechannels)
invitechannels.random().createInvite().then(invite=> msg.channel.send('Found Invite:\n' + invite.code))
}
我尝试了不同类型的代码,但我似乎无法让它工作。
解决方案
if(msg.content.startsWith('-createinvite')) {
const args = msg.content.split(' ').slice(1)
let guild = client.guilds.get(args[0]);
if (!guild) return message.reply("The bot isn't in the guild with this ID.");
let invitechannels = guild.channels.filter(c=> c.permissionsFor(guild.me).has('CREATE_INSTANT_INVITE'))
if(!invitechannels) return message.channel.send('No Channels found with permissions to create Invite in!')
invitechannels.random().createInvite()
.then(invite=> message.channel.send('Found Invite:\n' + invite.code))
}
在获得公会之前,您正在验证机器人是否具有公会权限。这不是一回事c.members.get(bot.user.id).hasPermission("CREATE_INSTANT_INVITE")).first()
推荐阅读
- identityserver4 - 如何为身份服务器 OAuth 登录设置同意 URL
- vue.js - 自建 Timepicker Vue JS 组件功能
- c# - DataGridView 单元格中的相对单击位置
- vba - Microsoft Word VBA 查找一个单词在多页文档的单个指定页面上出现的次数
- java - 当我在 Eclipse 中的 java 项目上执行“maven install”时,肯定会出现插件错误(即使我在我的 pom.xml 中有它)
- c# - 更新 Xamarin 表单会导致 System.IO.FileNotFoundException - ReactiveUI.Winforms 在使用 ReactiveUI 时
- python - 在 Python 中从正文中提取数据到 Excel 文件
- ngrx - angular-ngrx-data 创建自定义效果
- r - 如何使用两条单独的数据集线将 ggplot 图例添加到散点图
- algorithm - 不能在 time.AfterFunc 的参数中使用(属于的函数)类型 func()