0
votes

With my bot, I am trying to make it so that when a person gets the 'Prisoner' role, the bot automatically moves them into the 'jail' voice channel if they are already in a voice channel. I have tried lots of solutions from other stackoverflow threads, github threads and the documentation but none of them work.

class Jail(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

@commands.command()
    async def jail(self, ctx, person: discord.Member):
        try:
            jailor = discord.utils.find(lambda r: r.name == 'Jailor', ctx.message.guild.roles)
            if jailor in ctx.author.roles:
                prisoner = discord.utils.find(lambda r: r.name == 'Prisoner', ctx.message.guild.roles)
                await person.add_roles(prisoner)

                jail_vc = self.bot.get_channel('jail')
                await person.move_member(jail_vc)

            else:
                await ctx.send("You need to have the Jailor role to use this command")

        except Exception as e:
            print(str(e))

That code returns: 'Member object has no attribute 'move_member' Other things I have tried:

  • await self.bot.move_member(person, jail_vc)
  • await commands.move_member(person, jail_vc)
  • await command.move_member(person, jail_vc)
  • await ctx.guild.move_member(person, jail_vc)

And some other variations. The error is always 'something' has no attribute 'move_member' I am using the rewrite branch. How can I implement moving a person from any voice channel into the specific voice channel 'jail'? Any help will be greatly appreciated :).

1
"I have tried lots of solutions from other stackoverflow threads, github threads and the documentation" Did the documentation say that any of these things have a move_member method? Did the stackoverflow threads show code that says move_member in it? What did they say? What solutions did you try? - Karl Knechtel
@KarlKnechtel some of the solutions that I tried are in the question near the bottom. All the solutions I found were different variations of the move_member and alot of them were also for the old branch of discord.py. - BobDigby

1 Answers

1
votes

The function you're looking for is Discord.Member#move_to

You need to pass a VoiceChannel as it's param for the task you want to do. You may also provide a reason: str as the 2nd param.

await person.move_to(jail_vc, "Jail role")