I get this error on my bot when mentioning a role,here is the error,
raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: unhashable type: ‘set’
my code:
import os import discord from discord.ext import commands from discord import Intents from apikeys import * intents = Intents.all() client = commands.Bot(intents = intents, command_prefix="-", case_insensitive=True) @client.event async def on_ready(): for emoji in client.emojis: print("Name:", emoji.name + ",", "ID:", emoji.id) print('Bot is Online {0.user}'.format(client)) print("--------------------------------------------------------------------------------------------------------------------------------------------------------") client.remove_command('help') emojigood = 'N{THUMBS UP SIGN}' emojibad="N{THUMBS DOWN SIGN}" @client.command() async def war(ctx): await client.wait_until_ready() embed = discord.Embed(title='War', description='You are starting a war, do you want to continue?', color=0x00000) msg = await ctx.send(embed=embed) await msg.add_reaction(emojigood) await msg.add_reaction(emojibad) def check(r, user): return (r.emoji == emojigood or r.emoji == emojibad) and r.message == msg and user != client.user r, user = await client.wait_for('reaction_add',check=check) if r.emoji == emojigood: embed = discord.Embed(title='War', description='Please now choose a country', color=0x00000) await ctx.send(embed=embed) def check(msg): return msg.author == ctx.author and msg.channel == ctx.channel msg = await client.wait_for('message', check=check) if len(msg.role_mentions) > 0: role = msg.role_mentions[0] channel = client.get_channel({849549009038344262}) await channel.send(f"{role.mention} {ctx.author} has declared war on you.") else: await ctx.send("Invalid role mentioned") else: await ctx.send("Cancelled") client.run(token)
What’s meant to happen: Me:-war Bot:Are you sure Me:reacts Bot:Type in role Me:(role name) Bot:….
Advertisement
Answer
{849549009038344262}
is a set literal for a set containing a number. discord.py is using hashing under the hood to look up channels, which is failing because it is not possible to hash sets. You should be passing a regular int
instead of a set:
channel = client.get_channel(849549009038344262)