inputdiscord.pychannelvoicedisconnect

Disconnecting users from a Channel if guess is wrong DiscordPy


I'm coding a Discord bot. I made this command where it plays a little guessing game with a random integer from 1 to 10. If the guess from the user is correct, just a message pops out. If not, it disconnects the user from the voice channel, if it's in one.

This is the code I'm working on:

@bot.command()
async def adivinar(ctx: commands.Context):
    user = discord.Member
    aleatorio = random.randint(1,10)
    await ctx.send(f"Guess a number from 1 to 10")

    msg = await bot.wait_for("message")

    if int(msg.content) == aleatorio:
        await ctx.send(f"Congrats! My number was {aleatorio}")
    else:
        await ctx.send(f"Nope. My number was {aleatorio}")
        await user.move_to(None)

This code doesn't work. It shows this error in the terminal:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: move_to() missing 1 required positional argument: 'channel'

In order to make the "adivinar" command, I look into this piece of code as reference that works wonderfully:

@bot.command()
async def kick1(ctx: commands.Context, user: discord.Member):
    await ctx.send(f'{user.mention} has been kicked from {user.voice.channel.mention}')
    await user.move_to(None)

I'm pretty sure this is very easy to solve. But at the moment it's kinda hard for me to figure it out. Thanks!


Solution

  • you assigned user to the discord.Member class, not to a real member

    user = discord.Member
    

    you need to do something like ⬇ to can move it

    user = ctx.guild.get_member(1234)  # user id
    

    in your case you can also use user = msg.author