【发布时间】:2021-11-05 06:44:00
【问题描述】:
我目前正在开发一个文本到图像的生成机器人,我希望它能够发送实时消息,其中包含有关生成剩余时间、迭代和生成速度的信息,所有这些都可以找到在控制台中,但我不知道如何将控制台输出发送到不和谐。
【问题讨论】:
标签: discord console discord.py output
我目前正在开发一个文本到图像的生成机器人,我希望它能够发送实时消息,其中包含有关生成剩余时间、迭代和生成速度的信息,所有这些都可以找到在控制台中,但我不知道如何将控制台输出发送到不和谐。
【问题讨论】:
标签: discord console discord.py output
我假设您正在使用 print("output") 打印到控制台。
您可以通过Messageable#send()将消息发送到 Discord
例如发送到频道将是
await channel.send(content="content")
您可以通过多种方式获取Messageable
# In a cog
channel = ctx.channel
# In a cog you can directly use ctx.send() however
# In a on_message event
channel = message.channel
现在很简单,将您要打印的任何内容发送到控制台到 Discord
# Printing to console
print("hello world")
# Sending to message
await channel.send(content="hello world")
这种方法可能有点“垃圾邮件”,因此更好的做法是编辑消息
# 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")
【讨论】: