简体   繁体   中英

discord.py | I tried to make my discord bot send me a invite to specific servers it is connection to that are in a db but my current code doesn't work

@bot.command()
async def link(ctx, *, guild_name):
     mm = bot.get_guild(db[guild_name])
     guild_id = db[guild_name]
     a_guild = bot.get_guild(guild_id)
    
    
     server = bot.get_guild(mm)
    
    
     print("test1")
     for a_channel in a_guild.channels:
        bot_me = a_guild.me 
        bot_permissions = a_channel.permissions_for(bot_me)
        if bot_permissions.create_instant_invite: 
            break 
     else:
        return
     
     print("test2")
    
     link = await ctx.channel.create_invite(destination=server,xkcd=True, max_age=0,max_uses=1)
     print("test3")
     link = a_channel.channel.create_invite()
     print("test4")
    
    
     await ctx.send(link)

I get up to test3 and then it gives me a AttributeError: 'voicechannel' object has no attribute to 'channel', i also removed instant and it seemed to fix it but instead t runs only test1 and gives another AttributeError: 'Permissions' object has no attribute to 'create_invite'

@bot.command()
@commands.has_role('elite')
async def link(ctx, *, guild_name):
     mm = bot.get_guild(db[guild_name])
     guild_id = db[guild_name]
     a_guild = bot.get_guild(guild_id)
    
    
     server = bot.get_guild(mm)
    
    
     
     for a_channel in a_guild.channels:
        bot_me = a_guild.me 
        bot_permissions = a_channel.permissions_for(bot_me)
        if bot_permissions.create_instant_invite: 
            break 
     else:
        return
     
    
    
     link = await ctx.channel.create_invite(destination=server,xkcd=True, max_age=0,max_uses=1)
     
     link = await a_channel.create_invite()
     
    
    
     await ctx.send(link)
``` #this is the new code that fully works

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