'Send the output of a function as a message - Discord.py

I've been writing something along the lines of a gambling bot as a learning project and have started with a basic game called 'Suicide' (simple game, bad name). As far as the game goes it works great however I would like to send the output of the function 'rolls' as a message into the channel the command was ran in.


    @commands.command()
    async def Suicide (self, ctx, StartNum, wager):
        ID = (ctx.author.id)

        con = sl.connect('balance.db')

        with con:
            CheckBalance = con.execute(f"SELECT Balance FROM USER WHERE DiscordID = {ID}").fetchone()
            CleanBalance = str(CheckBalance).replace("(", "").replace(")" , "").replace("," , "")
            if int(wager) > int(CleanBalance):
                await ctx.send('You dont have the balance to wager that much')
            else:
                con.execute(f"""UPDATE USER
                SET Balance = Balance - {wager}
                WHERE DiscordID = {ID}; """)

                await ctx.send(f"🎲Starting game of suicide with a starting number of {StartNum}🎲")
                # await asyncio.sleep(2)

                StartNum = int(StartNum)

                def rolls():
                    Roll1_result = int(randrange(1, StartNum))
                    print(f"Roll Result is {Roll1_result} / {StartNum}")
                    while Roll1_result != 1:
                        Roll2_result = int(randrange(1, Roll1_result))
                        print(f"Roll result is {Roll2_result} / {Roll1_result}")
                        Roll1_result = int(Roll2_result)
                    else:
                        print("Reached 1")

                rolls()

Does anybody know of a way to do this if possible. Please excuse the messy code and variable names.

In case it is needed here is an example of the output i would like to send either in the form of an embed or a multi-line message

Roll result is 33 / 53
Roll result is 15 / 33
Roll result is 10 / 15
Roll result is 4 / 10
Roll result is 2 / 4
Roll result is 1 / 2
Reached 1


Solution 1:[1]

Replace print() with ctx.send() or

pastRolls = []
def rolls():
                    Roll1_result = int(randrange(1, StartNum))
                    pastRolls.append(f"Roll Result is {Roll1_result} / {StartNum}")
                    while Roll1_result != 1:
                        Roll2_result = int(randrange(1, Roll1_result))
                        pastRolls.append(f"Roll result is {Roll2_result} / {Roll1_result}")
                        Roll1_result = int(Roll2_result)
                    else:
                        pastRolls.append("Reached 1")
rolls()
for thing in pastRolls:
    ctx.send(thing)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pixeled