Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm making a Discord bot that is supposed to read from a text file and send called for line

I’m new to this coding space, and what I’m trying to do is have the discord bot respond to slash command with it’s specified line.

I have it where it works, but it responds to the command with the line below what is being called for. Here’s what I have so far

@slash.slash(name="f2pquest", description="Lists all available f2p quest")
async def f2pquest(ctx, *, word: str):
    await ctx.send('Checking File please stand by.')
    with open("f2pquest.txt", "r") as f:
        searching = re.compile(r'\b({0})\b'.format(word), flags=re.IGNORECASE).search
        line = True
        while line:
            line = f.readline()
            if not line:
                break
            if searching(line):
                await ctx.send(f.readline())
                return
    await ctx.send("Quest not found")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It should just be await ctx.send(line). f.readline() will read the next line below the line that has already been read.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading