Discord py 转发消息(带有嵌入)在一个频道上发送到另一个频道以及如何确定服务器中的成员数量?
Discord py forward messages(with embeds) sent on one channel to another and how to determine number of members in a server?
我想根据表情符号反应的反应数量将在特定频道上发送的消息转发到另一个频道。该消息有一些嵌入,由 YAGPDB.xyz 机器人从 sub reddit 发送。如果特定频道中的消息得到不止一个反对票反应,我想将该消息转发到另一个频道并在当前频道上删除它。这是来自此机器人的典型消息(带有嵌入),
我写了下面的代码,
@client.event
async def on_raw_reaction_add(payload):
if payload.channel_id in CHANNEL_LIST:
if payload.emoji.name=='\U0001F53C':
channel=client.get_channel(payload.channel_id)
message=await channel.fetch_message(payload.message_id)
reaction=get(message.reactions,emoji=payload.emoji.name)
if reaction and reaction.count>1:
await message.pin()
elif payload.emoji.name=='\U0001F53B':
channel=client.get_channel(payload.channel_id)
message=await channel.fetch_message(payload.message_id)
reaction=get(message.reactions,emoji=payload.emoji.name)
if reaction and reaction.count>1:
channel=client.get_channel(DELETED_MESSAGES_CHANNEL)
await channel.send('{}: {}'.format(message.author, message.content),embed=message.content.embeds)
await message.delete()
我收到以下错误,
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Python\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "s.py", line 46, in on_raw_reaction_add
await channel.send('{}: {}'.format(message.author, message.content),embed=message.content.embeds)
AttributeError: 'str' object has no attribute 'embeds'
如果我使用 embed=message.embeds
而不是 message.content.embeds
,我会收到以下错误,
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Python\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "s.py", line 46, in on_raw_reaction_add
await channel.send('{}: {}'.format(message.author, message.content),embed=message.embeds)
File "C:\Python\Python38\lib\site-packages\discord\abc.py", line 828, in send
embed = embed.to_dict()
AttributeError: 'list' object has no attribute 'to_dict'
如何获取此消息中的所有嵌入内容并将其转发到另一个频道?而且,我如何知道我的服务器中 NOT BOTS 的成员数量?非常感谢任何建议!
await channel.send('{}: {}'.format(message.author,message.content),embed=message.embeds[0])
通常,嵌入列表对象中只有一个嵌入。所以,在大多数情况下,只需使用 embeds[0]。到目前为止,我还没有看到包含多个嵌入的消息。
我想根据表情符号反应的反应数量将在特定频道上发送的消息转发到另一个频道。该消息有一些嵌入,由 YAGPDB.xyz 机器人从 sub reddit 发送。如果特定频道中的消息得到不止一个反对票反应,我想将该消息转发到另一个频道并在当前频道上删除它。这是来自此机器人的典型消息(带有嵌入),
@client.event
async def on_raw_reaction_add(payload):
if payload.channel_id in CHANNEL_LIST:
if payload.emoji.name=='\U0001F53C':
channel=client.get_channel(payload.channel_id)
message=await channel.fetch_message(payload.message_id)
reaction=get(message.reactions,emoji=payload.emoji.name)
if reaction and reaction.count>1:
await message.pin()
elif payload.emoji.name=='\U0001F53B':
channel=client.get_channel(payload.channel_id)
message=await channel.fetch_message(payload.message_id)
reaction=get(message.reactions,emoji=payload.emoji.name)
if reaction and reaction.count>1:
channel=client.get_channel(DELETED_MESSAGES_CHANNEL)
await channel.send('{}: {}'.format(message.author, message.content),embed=message.content.embeds)
await message.delete()
我收到以下错误,
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Python\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "s.py", line 46, in on_raw_reaction_add
await channel.send('{}: {}'.format(message.author, message.content),embed=message.content.embeds)
AttributeError: 'str' object has no attribute 'embeds'
如果我使用 embed=message.embeds
而不是 message.content.embeds
,我会收到以下错误,
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Python\Python38\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "s.py", line 46, in on_raw_reaction_add
await channel.send('{}: {}'.format(message.author, message.content),embed=message.embeds)
File "C:\Python\Python38\lib\site-packages\discord\abc.py", line 828, in send
embed = embed.to_dict()
AttributeError: 'list' object has no attribute 'to_dict'
如何获取此消息中的所有嵌入内容并将其转发到另一个频道?而且,我如何知道我的服务器中 NOT BOTS 的成员数量?非常感谢任何建议!
await channel.send('{}: {}'.format(message.author,message.content),embed=message.embeds[0])
通常,嵌入列表对象中只有一个嵌入。所以,在大多数情况下,只需使用 embeds[0]。到目前为止,我还没有看到包含多个嵌入的消息。