Discord Python Rewrite - Move channel

夙愿已清 提交于 2021-01-06 03:29:00

问题


Is it possible to move a channel on discord.py? Im making a nuke command that clones and deletes the channel, and it worked, but now i need to find out how to move the channel up to the origonal place, if there's a code / docs, please tell me a example. Thank's

Edit: I Got a working edit but it's always drags it on top, i need it so it will drag the channel to the same position before it got nuked.

My code that i currently have

@client.command()
@commands.has_permissions(manage_channels=True)
async def nuke(ctx):

    channel = ctx.channel

    await channel.clone()
    await channel.delete()
    await channel.edit(position=0, sync_permissions=True)
    return

回答1:


You can use await channel.edit(position=0) to change the position. In this case, since 0 is specified, the channel will be moved to the first position.

If you want to move it to the deleted channel's position then you can check channel.position.

@client.command()
@commands.has_permissions(manage_channels=True)
async def nuke(ctx):
    
    channel = ctx.channel
    channel_position = channel.position
    
    new_channel = await channel.clone()
    await channel.delete()
    await new_channel.edit(position=channel_position, sync_permissions=True)
    return


来源:https://stackoverflow.com/questions/63950798/discord-python-rewrite-move-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!