【发布时间】:2022-02-12 00:46:23
【问题描述】:
我已经开始使用 discord.py 制作 Ticket bot,但我的代码中有一个错误,我不知道如何解决它。嵌入并对消息工作做出反应,但是当我尝试做出反应时,一切都崩溃了。这是我的错误:
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
我希望有人知道如何解决这个问题,这是我当前的代码:
import discord
from discord.ext import commands
from discord.utils import get
from discord import Embed, Color
import DiscordUtils
import os
from discord.ext.commands import has_permissions, MissingPermissions
import json
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix = "-", intents = intents)
client.remove_command("help")
@client.command(pass_context=True)
async def ticket(ctx):
guild = ctx.guild
embed = discord.Embed(
title = 'Ticket system',
description = 'React ???? to make a ticket.',
color = 0
)
embed.set_footer(text="ticket system")
msg = await ctx.send(embed=embed)
await msg.add_reaction("????")
reaction = await msg.fetch_message(msg.id)
await client.wait_for("reaction_add")
await client.wait_for("reaction_add")
if reaction == '????':
await guild.create_text_channel(name=f'ticket - {reaction.author.name}')
ps:我是 discord.py 的新手
【问题讨论】:
标签: python python-3.x discord discord.py