Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.94k stars 3.77k forks source link

jail command & find a channel #994

Closed rektile closed 6 years ago

rektile commented 6 years ago

so i made a command that jails people for a 1 minute. to unjail someone i delete the channel. i want to write some code that checks if the jail channels still exists but it gives me errors

@bot.command(pass_context=True)
@commands.has_role(name="God's")
async def jail(ctx): 
    victim = ctx.message.mentions[0]
    timeout = time.time() + 60 ############1 min##################### 
    jail_channel = await bot.create_channel(ctx.message.server, "jail", type=discord.ChannelType.voice)
    await bot.move_member(victim, jail_channel)
    print(ctx.message.author, "jailed", victim, "for 60 seconden") 
    while time.time() < timeout: 
        print(victim, "is still jailed for ", timeout - time.time(), "seconds")
        ''' some code placed here thats checks if the channel still exists if it exists continue else break the loop '''
        await bot.move_member(victim, jail_channel) 
        await asyncio.sleep(1)
    try: 
        await bot.delete_channel(jail_channel)
        print("channel is deleted") 
     except: 
        print("channel is already deleted")

if you could help me it would be nice :D btw i know the code isnt clean , im still learning :p

jwshields commented 6 years ago

This doesn't seem to be a library issue, try asking in the discord.py chat https://discord.gg/r3sSKJJ

rektile commented 6 years ago

the code works but i didnt make something that unbans someone so i want o make something that checks if the jail channel still exists

rektile commented 6 years ago

do you know a way how i let the bot loop trough all the channels in my server and look if jail channel still exist ?

jegfish commented 6 years ago

Use utils.get http://discordpy.readthedocs.io/en/async/api.html#discord.utils.get.

Also if you need more help join the server jwshields linked you to.

Rapptz commented 6 years ago

These issues are not meant for questions regarding how to implement bot features.

rektile commented 6 years ago

Altarrel ty man :D