samedi 24 avril 2021

getting context under which your task is working with discord.py and asyncio

I have code that looks like this

bot = commands.Bot(command_prefix='!')

@bot.command(name="nv", description='For when you wanna get notional value')
async def getNotional(ctx):
    """Gets notional value of account"""
    await ctx.send("getNotionalValueOfAcct()")

@bot.command(name="delta", description='For when you wanna get beta weighted delta v spy')
async def getBetaWeightedDelta(ctx):
    """Gets delta"""
    await ctx.send("getBetaWeightedDelta()")

@bot.command(name="kill", description='For when you wanna kill the program')
async def killProgram(ctx):
    """kills running gram"""
    await ctx.send("program is being killed")
    bot.loop.stop()
    bot.loop.close()
    sys.exit()

bot.loop.create_task(something())
bot.run(TOKEN)

I want while im in the function something to be able to understand i'm working under the bot context so that i can send a message based on certain events on the code. Is this possible? I really would rather not pass bot through every function in the program

Aucun commentaire:

Enregistrer un commentaire