I have been trying to create a discord bot that uses buttons for my DnD group. Interestingly, when I try to run the following code I get an error message saying the hitResult in fucntion callback1 does not have a value. However, the other variable, hitResult2, I pass in the exact same way is defined. I also pass the same variable, hitResult, into function callback1 and the code has no problem with it. Anyone come across this before? Many thanks
async def rangedButtons(message, hitResult, hitResult2, dmgResult, weapon):
#view.clear_items()
button1 = Button(label="Yes", style=discord.ButtonStyle.green)
button2 = Button(label="No", style=discord.ButtonStyle.red)
print(hitResult)
print(hitResult2)
async def callback1(interaction):
view.clear_items()
# This will need to handle the input based on what button was pressed
await interaction.response.edit_message(content="**"+weapon.name+"**" + message.author.mention + "\nAttack roll: " + str(hitResult), view=view)
hitMissButtons(message, dmgResult, weapon)
async def callback2(interaction):
view.clear_items()
print(hitResult)
print(hitResult2)
if hitResult2 < hitResult:
hitResult = hitResult2
print(hitResult)
await interaction.response.edit_message(content= "**"+weapon.name+"**" + message.author.mention + "\nAttack roll: " + str(hitResult), view=view)
hitMissButtons(message, dmgResult, weapon)
button1.callback = callback1
button2.callback = callback2
view = View()
view.add_item(button1)
view.add_item(button2)
await message.reply(view=view)
I would expect this to work the same way as for hitResult2 and function callback1, but computer says no...
Tried creating global hitResult in callback2 with no result