Here are skeleton versions of my code:
bot.py
import discord
client = discord.Client()
async def send_notification(notification):#this method is tested and works when called from same file
for guild in client.guilds:
for channel in guild.text_channels:
if channel.name == CHANNEL_NAME:
await channel.sent(notification)
def start_bot():
client.run(TOKEN)
def notification(notification):
asyncio.create_task(send_notification(notification))#likely error here
main.py
import bot
from time import sleep
def main():
bot.start_bot()
sleep(10)
bot.notification('some notification')
main()
Hello, I am trying to send a message to all guilds from a different python file. I understand that I am making some fundamental error with how asynchronous tasks are handled. Currently main.py doesn't even get to the sleep() statement.
- Is there some way to reference the client from main.py so that it would be possible to call methods with it
- Could I create some api so any python file can access methods inside the bot
Thanks in advance.