I am trying to use the discord.py library to send messages to a channel using it's name.
This library is asynchronous and I have problems with sending more than 1 message. when I try to send a message afer the send function has already been called, I get this
Task exception was never retrieved
future: <Task finished name='Task-13' coro=<send() done, defined at C:\Users\paula\DiscordBot\Bot.py:65> exception=RuntimeError('cannot reuse already awaited coroutine')>
RuntimeError: cannot reuse already awaited coroutine
the send function :
async def send():
global en_message, en_ChannelName
guild = client.get_guild(some_guild_ID_you_want)
for channel in guild.channels:
if en_ChannelName.get().lower() in channel.name.lower() and type(channel) == discord.channel.TextChannel and en_ChannelName.get() != "":
await channel.send(en_message.get())
break
the code it is called by :
bt_Send = tk.Button(text="Send", command=partial(client.loop.create_task, send()))
I also have to mention that the discord client is running on a non-main thread (the code :
thread_runBot = t.Thread(target=partial(client.run, botToken))
thread_runBot.start()
TK_dialog.mainloop()
)