0

I am trying to make a discord bot featuring diagnoses for mild illnesses.

I want the bot to send a message prompting the user to send symptoms and see if any match a list of symptoms for a specific disease.

I can't figure out how to grab the user's input to compare it in the list.

I tried the check(m) method. While it does work with singular keywords, I am trying to clean up the code as much as possible by just checking the ctx to see if it's in the list.

allergy_symptoms = ["sneezing", "runny nose", "congestion", "cough", "wheezing", "shortness of breath", "itchy eyes", "hives", "rash", "itchiness"]

'''Wanted to use buttons in my bot, but if it must be removed I am willing to disband the feature'''
class MyView(discord.ui.View):
    @discord.ui.button(label = "Yes", style = discord.ButtonStyle.green)
    async def button_callback(self, interaction: discord.Interaction, button: discord.ui.button):
        await interaction.response.send_message("Excellent. To start, please list any symptoms you may be experiencing in a single message. For example: I have been experiencing congestion, sneezing, and a runny nose.")

@bot.command()
async def diagnose(ctx):
    await ctx.send(f'Hello, I am the R.E.M.E.D.Y. Bot. I can assist you with a diagnosis and recommend a remedy for it.Is this something you are looking for?', view = MyView())

    '''I need code here to accept user input to compare it in allergy_symptoms'''
    if ctx in allergy_symptoms:
            await ctx.send("You may have allergies.")
        else:
            await ctx.send("You might not have allergies)")
    
1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Although, I'm assuming that you're asking about the particular line with the if statement. Commented May 8 at 16:01

2 Answers 2

1

You need to get the raw string of the context. Instead of ctx, you need to use ctx.message.content instead.

    '''I need code here to accept user input to compare it in allergy_symptoms'''
    if ctx.message.content.split(" ")[1] in allergy_symptoms:
            await ctx.send("You may have allergies.")
        else:
            await ctx.send("You might not have allergies)")
Sign up to request clarification or add additional context in comments.

4 Comments

ctx.message.content = "!diagnose <whatever symptom>" it's never gonna be in the allergy_symptoms list.
You can split the string. ctx.message.content.split(" ")[1] gets the first index or parameter of the command
Yeah or simply take it in as an argument: async def diagnose(ctx, *, symptom):
That's true. I honestly haven't worked with d.py that much but yeah (& I wrote this at school and don't have access to a dev environment rn). Also I completely neglected the discord.ui thing within the user's post which I should be able to add in a bit.
0

Found a way to check user input in a list, am removing the MyView() class and buttons for the time being. I tried using any(), which requires me to use str() on message.content as any() will not take in ctx objects or parameters.

@bot.command()
async def diagnose(ctx):
    await ctx.send(f'Hello, I am the R.E.M.E.D.Y. Bot. I can assist you with a diagnosis and recommend a remedy for it.'
                   'What symptom are you mainly experiencing?')
    
    def check(message):
        return message.author == ctx.author and message.channel == ctx.channel 

    try:
        message = await bot.wait_for('message', check = check)
    except asyncio.TimeoutError:
        await ctx.send("You took too long to respond. The command has closed.")
  
    
    if any(str(message.content) in item for item in allergy_symptoms):
        await ctx.send("Thank you for sharing your symptoms. To help me with your diagnosis, please tell me if you've experienced any of the following symptoms below:")

        final_string = print_list_no_string(allergy_symptoms, message.content)
   
        await ctx.send('\n'.join(final_string))

        def check(message):
            return message.author == ctx.author and message.channel == ctx.channel
        
        try:
            message = await bot.wait_for('message', check = check)
        except asyncio.TimeoutError:
            await ctx.send("You took too long to respond. The command has closed.")

        if message.content == "yes":
            await ctx.invoke(bot.get_command('allergy_diagnosis'))
            await ctx.invoke(bot.get_command('allergy_remedy'))
        
        else:
            await ctx.send("It seems that R.E.M.E.D.Y. Bot was unable to diagnose you. Please reach out to your primary care provider for support. Feel better.")


    else:
        await ctx.send("It seems that R.E.M.E.D.Y. Bot was unable to diagnose you. Please reach out to your primary care provider for support. Feel better.")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.