Let me start this by telling you guys that I am a complete noob with Discord bot development, so it might be something that I am doing wrong. I will appreciate it if you can provide me with any guidance. Thank you in advance.
Describe the bug
While testing the example(https://github.com/terabyte3/discord-ext-forms) that you guys have on the main page of this repo, I keep getting the error below:
Ignoring exception in command testform:
Traceback (most recent call last):
File "C:\Users\rosorio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\rosorio\Documents\PersonalProject\Discord_Trade_Bot\bot.py", line 65, in testform
result = await form.start()
File "C:\Users\rosorio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\forms\form.py", line 297, in start
if correct:
UnboundLocalError: local variable 'correct' referenced before assignment
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\rosorio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\rosorio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\rosorio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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: UnboundLocalError: local variable 'correct' referenced before assignment
To Reproduce
I am using Python -V 3.9.7. Also, I installed these requirements:
discord.py
python-dotenv==0.13.0
discord.ext.forms
furo
Sphinx==3.5.4
numpydoc
`import os
import json
import re
import discord
import random
from os.path import join, dirname
from discord import message
from discord import client
from discord.ext.forms.helpers import channel
from dotenv import load_dotenv
from discord.utils import get
#from discord.ext.forms.form import Validator
from discord.ext.forms import Form
from discord.ext import commands
DISCORD_TOKEN = os.environ.get('DISCORD_TOKEN')
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
""" Runs once the bot has established a connection with Discord """
print(f'{bot.user.name} has connected to Discord')
# check if bot has connected to guilds
if len(bot.guilds) > 0:
print('connected to the following guilds:')
for guild in bot.guilds:
print(f'* {guild.name}#{guild.id}')
@bot.command(name="test")
@commands.has_role("Admin")
async def on_test(ctx):
guild = ctx.guild
channel = ctx.channel
author = ctx.author
command = ctx.message.content
# log event on command line
print(f'* "{author.name}" issued "{command}" in "{channel}" of "{guild}"')
# post random GIF from the JSON file
await channel.send(f'* "{author.name}" issued "{command}" in "{channel}" of "{guild}"')
@bot.command()
async def testform(ctx):
form = Form(ctx,'Title')
form.add_question('Question 1','first')
form.add_question('Question 2','second')
form.add_question('Question 3','third')
result = await form.start()
embed=discord.Embed(title="details", description=f"1st: `{result.first}`\n 2nd: `{result.second}`\n 3rd: `{result.third}`")
await ctx.send(embed=embed)
if name == "main":
# launch bot
bot.run(TOKEN)`
Expected behavior
the same mechanic that you guys are displaying on the main page of this repo.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- Windows 10 pro
- Visual Studio Code
Additional context
Add any other context about the problem here.
bug