I'm creating a menu system for my Discord bot by using buttons and select menus. So far I've had to control this flow by calling the next function from within the button, or else my code will continue without waiting for a decision to be made, and if I try using while loops it will just repeatedly spam the menu.
This currently will display the drop down menu of characters to select when added to a standard View() and sent to the user, but the problem lies in the callback.
I would prefer my code waits for the choice to be made and the value returned to the "main loop" for further operations to be made. Is this possible?
import os
from discord.ext import commands
import discord
class Select_character(discord.ui.Select):
def __init__(self, choices):
super().__init__()
for each in choices:
self.options.append(discord.SelectOption(label=each['name'], description=each['unit']))
async def callback(self, ctx):
return self.values
TOKEN = '{bot_token}'
prefix = "!"
client = commands.Bot(command_prefix=prefix, case_insensitive=True)
test_case = [{"name" : "John", "unit" : "Fighter"}, {"name" : "Filip", "unit" : "Monk"}]
@client.event
async def on_ready():
print(f"We have logged in as {client.user}")
@client.event
async def on_message(ctx):
if not ctx.author.bot:
choices = Select_character(test_case)
view = discord.ui.View()
view.add_item(choices)
await ctx.channel.send(content="Make a Choice", view=view)
print(choice_made)
client.run(TOKEN)