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:
            if searching(line):
                await ctx.send(f.readline())
    await ctx.send("Quest not found")

>Solution :

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

Leave a Reply