I want to ask a discord client to execute a specific function WITHOUT being triggered by an on message, or on ready or having a LOOP that repeats itself.
Basically, I want a function notify(msg) and make the discord client send a message to a channel
I have tried with the following without success
async notify(message, client):
await client.wait_until_ready()
channel = client.get_channel(os.getenv('CHANNEL_ID'))
await channel.send(message)
client.run(os.getenv('CLIENT_TOKEN'))
# Notice that I try to run the task after the client run
# Because I may call notify multiple times after the client has been created
client.loop.create_task(notify())
I want to invoke this function after the client has been created and without looping indefinitely.
Tried also to run
asyn def main():
await client.connect()
await client.log(client.run(os.getenv('CLIENT_TOKEN')))
await notify('My message', client)
# then
if __name__ = "__main__":
asyncio.run(main())
This just doesnt run ... having errors with http requests and so on.