我正在学习discordPy,并且试图获取对特定消息做出反应的用户列表(名称/ ID)。以下是我的代码:
async def ga(self, ctx):
channel = ctx.channel
users = ""
async for message in channel.history(limit=200):
if message.id == '613850569718890495':
reactions = message.reactions
async for user in reactions.users():
users += user.name + ", "
await ctx.send(content=f"user: {users}")
我没有收到任何错误消息,但也没有得到任何结果。您能指出我的代码有什么问题吗?谢谢
答案 0 :(得分:1)
ID是整数,而不是字符串,Reaction.users
是AyncIterator
,而Message.reactions
是常规列表
channel_id = 12345 # Replace with channel id
message_id = 613850569718890495 # Note these are ints, not strings
@commands.command()
async def ga(self, ctx):
channel = self.bot.get_channel(channel_id)
message = await channel.fetch_message(message_id)
users = set()
for reaction in message.reactions:
async for user in reaction.users():
users.add(user)
await ctx.send(f"users: {', '.join(user.name for user in users)}")