【问题标题】:Getting error on discord bot discord.py for typing in role在不和谐机器人 discord.py 上输入角色时出错
【发布时间】:2021-08-23 00:55:09
【问题描述】:

我在提到角色时在我的机器人上收到此错误,这是错误,

从 exc 中引发 CommandInvokeError(exc) discord.ext.commands.errors.CommandInvokeError:命令引发异常:TypeError:unhashable type:'set'

我的代码:

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)

会发生什么: 我:-战争 博特:你确定吗 我:反应 机器人:输入角色 我:(角色名) 机器人:....

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:
    {849549009038344262}
    

    是包含数字的集合的集合文字。 在后台使用散列来查找频道,但由于无法散列集合而失败。你应该传递一个普通的int 而不是一个集合:

    channel = client.get_channel(849549009038344262)
    

    【讨论】:

      猜你喜欢
      • 2019-02-02
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 2021-01-06
      • 1970-01-01
      • 2021-01-22
      • 2021-08-13
      • 2018-11-17
      相关资源
      最近更新 更多