[英]How to make a discord bot to create a invite in other guild
I can't get the bot to make a invite on another guild the bot is in. 我无法让该机器人向该机器人所在的另一个公会发出邀请。
I've tried giving my bot the adminstrator role to make sure it has permissions. 我尝试为我的机器人赋予管理员角色,以确保其具有权限。
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))
}
I've tried different kind of codes but I can't seem to get this to work. 我尝试了不同类型的代码,但似乎无法正常工作。
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))
}
You were verifying if the bot has permissions for a guild before getting the guild. 您在获取公会之前正在验证该机器人是否具有公会的权限。 And this is not a thing c.members.get(bot.user.id).hasPermission("CREATE_INSTANT_INVITE")).first()
这不是c.members.get(bot.user.id).hasPermission("CREATE_INSTANT_INVITE")).first()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.