Discord.py 票务系统

时间:2021-02-24 16:00:25

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

我已经开始使用 discord.py 制作 Ticket bot,但我的代码中有错误,我不知道如何解决。嵌入并对消息做出反应,但是当我尝试对所有内容做出反应时,一切都崩溃了。这是我的错误:

google.charts.setOnLoadCallback

我希望有人知道如何解决这个问题,这是我当前的代码:

Ignoring exception in command ticket:
Traceback (most recent call last):
  File "C:\Users\HP\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\HP\Desktop\222\dscbot-dscbot.py", line 150, in ticket
    if reaction == '?':
NameError: name 'reaction' is not defined

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

Traceback (most recent call last):
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\HP\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: NameError: name 'reaction' is not defined

ps:我是 discord.py 的新手

2 个答案:

答案 0 :(得分:1)

reaction = await msg.fetch_message(msg.id) 只是给你 msg。相反,您需要从 await client.wait_for("reaction_add")

获得反应

看看wait_for。您执行一个检查(即反应所在的位置)以查看反应是否是邮箱。

如果反应是邮箱,您需要创建一个新函数来创建通道,然后将其传递给 client.wait_for

def check(reaction, user):
    return str(reaction) == '?' and ctx.author == user

await client.wait_for("reaction_add", check=check)
await guild.create_text_channel(name=f'ticket - {ctx.author}')

答案 1 :(得分:0)

您没有定义 reaction,这就是引发此错误的原因。 查看 this post 以了解如何从消息中获取反应。

相关问题