如何修复此"Ghost"错误?



我知道如何正常打印嵌入,但这次它令人困惑。我甚至在不同的if语句中创建了每个单独的嵌入。

代码:


@client.command()
async def quizintsci(ctx,*, unit):
unit = int(unit)
if unit == 1:
answer = ""
wrongAnswer1 = ""
wrongAnswer2 = ""
obvWrongAnswer = ""
questions1=["Which of these observations are qualitative observations?","I","FairOPShotgun","FairOPBot","She","He","No_lucas"]
answerToExpect = ""
questionNum = random.randint(0,len(questions1)-1)
questionToAsk = questions1[questionNum]
if questionNum == 0:
correctAnswer = ["Luster", "Color", "Brightness", "Smoothness"]
wrongAnswer = ["Time", "Price", "Height", "Weight", "Volume", "Density", "Percentage", "Ratio", "Money", "Statistics", "John weighs 90 pounds", "The volume of a sphere is 200cm^3", "There are 100 people living in this town", "Each class has 16 students", "Age", "Temperature"]
obviouslyWrongAnswers = ["Dog", "X+Y=13", "I have a pencil case", "The camera took a picture", "I love english class", "Popcorn", "Microphone"]
answer = correctAnswer[random.randint(0, len(correctAnswer) -1)]
wrongAnswer1 = wrongAnswer[random.randint(0, len(wrongAnswer) -1)]
wrongAnswer2 = wrongAnswer[random.randint(0, len(wrongAnswer) -1)]
obvWrongAnswer = obviouslyWrongAnswers[random.randint(0, len(obviouslyWrongAnswers) -1)]
randomNum = random.randint(0, 3)
if randomNum == 0:
embedQuiz = discord.Embed(title="", description="", color=0xFFFFFF)
embedQuiz.set_author(name="Science Question", url= "https://youtube.com/fairopshotgun",icon_url="https://cdn.discordapp.com/emojis/859474000145154098.png?v=1")
embedQuiz.add_field(name = questionToAsk, value = "** **", inline = True)
embedQuiz.add_field(name = "A: ", value = answer, inline = False)
embedQuiz.add_field(name = "B: ", value = wrongAnswer1, inline = True)
embedQuiz.add_field(name = "C: ", value = wrongAnswer2, inline = False)
embedQuiz.add_field(name = "D: ", value = obvWrongAnswer, inline = True)
embedQuiz.set_footer(text='https://youtube.com/fairopshotgun',icon_url="https://media.discordapp.net/attachments/861325953191116813/895753939276931082/download.jpeg")
await ctx.reply(embed = embedQuiz, mention_author = False)
answerToExpect = "A"
elif randomNum == 1:
embedQuiz = discord.Embed(title="", description="", color=0xFFFFFF)
embedQuiz.set_author(name="Science Question", url= "https://youtube.com/fairopshotgun",icon_url="https://cdn.discordapp.com/emojis/859474000145154098.png?v=1")
embedQuiz.add_field(name = questionToAsk, value = "** **", inline = True)
embedQuiz.add_field(name = "A: ", value = wrongAnswer1, inline = False)
embedQuiz.add_field(name = "B: ", value = answer, inline = True)
embedQuiz.add_field(name = "C: ", value = wrongAnswer2, inline = False)
embedQuiz.add_field(name = "D: ", value = obvWrongAnswer, inline = True)
embedQuiz.set_footer(text='https://youtube.com/fairopshotgun',icon_url="https://media.discordapp.net/attachments/861325953191116813/895753939276931082/download.jpeg")
await ctx.reply(embed = embedQuiz, mention_author = False)
answerToExpect = "B"
elif randomNum == 2:
embedQuiz = discord.Embed(title="", description="", color=0xFFFFFF)
embedQuiz.set_author(name="Science Question", url= "https://youtube.com/fairopshotgun",icon_url="https://cdn.discordapp.com/emojis/859474000145154098.png?v=1")
embedQuiz.add_field(name = questionToAsk, value = "** **", inline = True)
embedQuiz.add_field(name = "A: ", value = wrongAnswer1, inline = False)
embedQuiz.add_field(name = "B: ", value = wrongAnswer2, inline = True)
embedQuiz.add_field(name = "C: ", value = answer, inline = False)
embedQuiz.add_field(name = "D: ", value = obvWrongAnswer, inline = True)
embedQuiz.set_footer(text='https://youtube.com/fairopshotgun',icon_url="https://media.discordapp.net/attachments/861325953191116813/895753939276931082/download.jpeg")
await ctx.reply(embed = embedQuiz, mention_author = False)
answerToExpect = "C"
elif randomNum == 3:
embedQuiz = discord.Embed(title="", description="", color=0xFFFFFF)
embedQuiz.set_author(name="Science Question", url= "https://youtube.com/fairopshotgun",icon_url="https://cdn.discordapp.com/emojis/859474000145154098.png?v=1")
embedQuiz.add_field(name = questionToAsk, value = "** **", inline = True)
embedQuiz.add_field(name = "A: ", value = wrongAnswer1, inline = False)
embedQuiz.add_field(name = "B: ", value = wrongAnswer2, inline = True)
embedQuiz.add_field(name = "C: ", value = obvWrongAnswer, inline = False)
embedQuiz.add_field(name = "D: ", value = answer, inline = True)
embedQuiz.set_footer(text='https://youtube.com/fairopshotgun',icon_url="https://media.discordapp.net/attachments/861325953191116813/895753939276931082/download.jpeg")
await ctx.reply(embed = embedQuiz, mention_author = False)
answerToExpect = "D"
userInput = await client.wait_for("message")
if str(userInput.content) == answerToExpect:
await ctx.send("NO WAY! You got the question correct, " + ctx.message.author.display_name + "!")

else:
await ctx.send("RIP!! "+ ctx.message.author.display_name+ ", you got the question wrong! The correct answer was *" + str(answer) + "*.")

当我使用命令时,它没有显示任何东西。我得到了一个错误

错误:

Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 152, in quizintsci
await ctx.reply(embed = embedQuiz, mention_author = False)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/context.py", line 340, in reply
return await self.message.reply(content, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/message.py", line 1358, in reply
return await self.channel.send(content, reference=self, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 1065, in send
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 254, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed.fields.1.value: This field is required
In embed.fields.2.value: This field is required
In embed.fields.3.value: This field is required
In embed.fields.4.value: This field is required
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/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: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed.fields.1.value: This field is required
In embed.fields.2.value: This field is required
In embed.fields.3.value: This field is required
In embed.fields.4.value: This field is required

为什么会这样?我显然为每个嵌入设置了值,所以我不知道为什么它说该字段是必需的。

只有当变量questionNum为0时,您的答案才会得到定义。因此,当questionNum不为0时,嵌入字段都为空。

我不确定你的最终结果应该是什么样子,但是你可以从randomNum = random.randint(0, 3)行开始缩进1,只在questionNum为0时使用这些答案,或者你可以从if questionNum == 0:块中选择定义答案的随机逻辑。两个都可以。