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:
JavaScript
x
50
50
1
import os
2
import discord
3
from discord.ext import commands
4
from discord import Intents
5
from apikeys import *
6
intents = Intents.all()
7
client = commands.Bot(intents = intents, command_prefix="-", case_insensitive=True)
8
9
10
11
@client.event
12
async def on_ready():
13
for emoji in client.emojis:
14
print("Name:", emoji.name + ",", "ID:", emoji.id)
15
print('Bot is Online {0.user}'.format(client))
16
print("--------------------------------------------------------------------------------------------------------------------------------------------------------")
17
client.remove_command('help')
18
19
20
emojigood = 'N{THUMBS UP SIGN}'
21
emojibad="N{THUMBS DOWN SIGN}"
22
23
@client.command()
24
async def war(ctx):
25
await client.wait_until_ready()
26
embed = discord.Embed(title='War', description='You are starting a war, do you want to continue?', color=0x00000)
27
msg = await ctx.send(embed=embed)
28
await msg.add_reaction(emojigood)
29
await msg.add_reaction(emojibad)
30
def check(r, user):
31
return (r.emoji == emojigood or r.emoji == emojibad) and r.message == msg and user != client.user
32
r, user = await client.wait_for('reaction_add',check=check)
33
if r.emoji == emojigood:
34
embed = discord.Embed(title='War', description='Please now choose a country', color=0x00000)
35
await ctx.send(embed=embed)
36
def check(msg):
37
return msg.author == ctx.author and msg.channel == ctx.channel
38
msg = await client.wait_for('message', check=check)
39
if len(msg.role_mentions) > 0:
40
role = msg.role_mentions[0]
41
channel = client.get_channel({849549009038344262})
42
await channel.send(f"{role.mention} {ctx.author} has declared war on you.")
43
else:
44
await ctx.send("Invalid role mentioned")
45
else:
46
await ctx.send("Cancelled")
47
48
49
client.run(token)
50
What’s meant to happen: Me:-war Bot:Are you sure Me:reacts Bot:Type in role Me:(role name) Bot:….
Advertisement
Answer
JavaScript
1
2
1
{849549009038344262}
2
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:
JavaScript
1
2
1
channel = client.get_channel(849549009038344262)
2