Frikallo
Frikallo

Reputation: 91

Discord Py Sending Live Python Output

I'm currently working on a text-to-image generation bot and I'd like it to send live messages with information about the time remaining in the generation, iteration, and speed at which it's generating, all can be found in the console but I have no idea how to send console output to discord.

Upvotes: 1

Views: 957

Answers (1)

user14505884
user14505884

Reputation:

I'm assuming you are using print("output") to print into the console.

You can send the message to Discord via Messageable#send()
For example sending to a channel would be

await channel.send(content="content")

You can get the Messageable in a lot of ways

# In a cog
channel = ctx.channel
# In a cog you can directly use ctx.send() however

# In a on_message event
channel = message.channel

Now simply, send whatever you are printing to the console to Discord

# Printing to console
print("hello world")

# Sending to message
await channel.send(content="hello world")

That approach can be a bit "spammy", so a better practice is to edit the message instead

# channel.send() returns the message

# Printing
print("status update")

# Sending message
message = await channel.send(content="status update")

# [Image generation code]

# Printing
print("new status update")

# Editing message
await message.edit(content="new status update")

Upvotes: 1

Related Questions