I need to send a message in the discord channel based on a trigger that occurs in my program. My program runs in one main "while True" loop. Ideally I'd like to call the "send_message(text, picture)" function.
What i have now:
class MyClient(discord.Client):
async def on_ready(self):
print(f'Logged on as {self.user}!')
async def on_message(self, message):
#This part work correctly, but that's not what I'm asking about.
if str(message.author)!='BOT' and message.content=="Show":
print(f'Message from {message.author}: {message.content} in {message.channel.id}')
is_success, buffer = cv2.imencode(".jpg", frame)
io_buf = io.BytesIO(buffer)
await message.channel.send(file=discord.File(io_buf, 'image.png'))
async def my_send(picture_to_send, text_to_send):
print("trying to send")
c_id=ID
channel_to = MyClient.get_channel(id=int(c_id))
is_success, buffer = cv2.imencode(".jpg", picture_to_send)
io_buf = io.BytesIO(buffer)
await channel_to.send(content=str(text_to_send), file=discord.File(io_buf, 'image.png'))
def dis_start():
intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run('TOKEN')
dis_Call = threading.Thread(target=dis_start, daemon=True)
dis_Call.start()
when i try MyClient.my_send(frame, text) i recieve error "RuntimeWarning: coroutine 'MyClient.my_send' was never awaited".
Maybe I'm trying to do it wrong, tell me how you would do it.