Bazzert6857
Bazzert6857

Reputation: 11

discord python error TypeError: unhashable type: 'list'

Im making a discord bot but its giving me a TypeError: unhashable type: 'list' error, i tried to fix it in alot of ways but still didnt work at all, yall mind helping me?

Code:

import discord
from discord.ext import commands
import random

intents = discord.Intents.all()
discord.members = True
intents.members = True
client = commands.Bot(command_prefix="!", intents=intents)

@client.command()
async def highLow(ctx: commands.Context):
    AceCard = [1]
    TwoCard = [2]
    ThreeCard = [3]
    FourCard = [4]
    FiveCard = [5]
    SixCard = [6]
    SevenCard = [7]
    EightCard = [8]
    NineCard = [9]
    TenCard = [10]
    JackCard = [11]
    QueenCard = [12]
    KingCard = [13]
    randomCard = random.choice({AceCard}, {TwoCard}, {ThreeCard}, {FourCard}, {FiveCard}, {SixCard}, {SevenCard}, {EightCard}, {NineCard}, {TenCard}, {JackCard}, {QueenCard}, {KingCard})
    embed = discord.Embed(title="Welcome to HighLow", description=f"You have {randomCard}", colour=0x87CEEB)
    embed.set_author(name="Anwais#6857")
    embed.add_field(name="Higher", value="React 1 for higher", inline=False)
    embed.add_field(name="Lower", value="React 2 for lower", inline=True) 
    global one
    one = client.get_emoji(946853495628238878)
    global two
    two = client.get_emoji(946853495716327504)
    messageBeforeCard1 = await ctx.channel.send(embed=embed)
    await messageBeforeCard1.add_reaction(one)
    await messageBeforeCard1.add_reaction(two)
    print("a")
    
@client.event
async def on_reaction_add(reaction, user, ctx: commands.Context):
        one= 1
        HigherLowerId = 0
        oneReaction = 0
        twoReaction = 0
        if reaction.emoji.id == one:
            if user.id == HigherLowerId :
                await ctx.send(f"You chose {one}")
                
            else:
                await reaction.message.channel.send(f"This is not your game, {user.mention}")
        elif reaction.emoji.id != oneReaction:
            pass 

Here is the Fulltrace back:

PS C:\Users\walid\Downloads\Main>  c:; cd 'c:\Users\walid\Downloads\Main'; & 'C:\Users\walid\AppData\Local\Programs\Python\Python39\python.exe' 'c:\Users\walid\.vscode\extensions\ms-python.python-2022.3.10741003\pythonFiles\lib\python\debugpy\launcher' '51596' '--' 'c:\Users\walid\Downloads\Main\HighLowCardGame.py' 
Ignoring exception in command highLow:
Traceback (most recent call last):
  File "C:\Users\walid\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:\Users\walid\Downloads\Main\HighLowCardGame.py", line 25, in highLow
    randomCard = random.choice({AceCard}, {TwoCard}, {ThreeCard}, {FourCard}, {FiveCard}, {SixCard}, {SevenCard}, {EightCard}, {NineCard}, {TenCard}, {JackCard}, {QueenCard}, {KingCard})
TypeError: unhashable type: 'list'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\walid\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke    await ctx.command.invoke(ctx)
  File "C:\Users\walid\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\walid\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: unhashable type: 'list'

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

Upvotes: 0

Views: 271

Answers (1)

Augusto
Augusto

Reputation: 91

The error is because you can not have a list inside a set. You are doing random.choice({[1]}, {[2]}) and so on.

Also, you might check the docs. random.choice receives just a sequence (one parameter), not multiple sequences. i.e.: random.choice([1, 2, 3, 4])

You should define a list and give that to random.choice, or better option is to use random.randint(1,13). This will pick one from 1 to 13, randomly.

Upvotes: 1

Related Questions