我希望我的 Discord.py 机器人显示来自单个通道的随机嵌入式消息



我有一个充满嵌入消息的discord通道我想让机器人在调用命令的任何其他通道中显示一条来自该通道的随机嵌入消息,类似于下面显示的功能

当我在指向嵌入通道时调用此代码时,它返回一个错误:";discord.errors.HTTPException:400错误请求(错误代码:50006(:无法发送空消息";

我相信这是由于频道被完全嵌入造成的,但我很愚蠢,愿意被纠正。我已经确认机器人拥有完全的管理权限,因此可以查看/写入任何频道。我还确认了以下代码适用于其他通道中的非嵌入

提前感谢您提供的任何帮助。

@client.command()
async def bestpost(ctx):
channel = client.get_channel(channelID)
best_posts = []
async for message in channel.history(limit=500):
best_posts.append(message)
random_bestpost = random.choice(best_posts).content
await ctx.send(random_bestpost)

如果通道是完全嵌入的,那么您必须查看消息的嵌入,而不是消息内容。从那里你可以发送嵌入,或者访问嵌入的属性并发送它。

例如:

@client.command()
async def bestpost(ctx):
channel = client.get_channel(channelID)
best_posts = []
async for message in channel.history(limit=500):
best_posts.append(message)
random_bestpost = random.choice(best_posts).embeds[0]
await ctx.send(embed=random_bestpost)

最新更新