当他们对某种反应做出反应时,如何将 Discord 用户 ID 添加到机器人嵌入消息中?
How to add Discord user ID to bot embed message when they react with a certain reaction?
我刚拿起 python 并在互联网、discord py API 和 Whosebug 上进行了一些搜索,但我仍然不确定如何让我的 discord 机器人正常工作。
当用户对机器人嵌入消息上的复选标记做出反应时,是否有办法获取不和谐用户 ID?
这是我的代码:
这部分有效:
#new dely ubjectiv
if msg.startswith('$new_dobj'):
ubj = msg.replace('$new_dobj ','')
embed = discord.Embed(title = "Dely Ubjectiv:", description = ubj +"\n\n**ppl hoo compleeted it:**", colour = 0x99dfff)
m = await message.channel.send(embed=embed)
await m.add_reaction('✅')
下面的代码似乎没有做任何事情。目标:当人们点击复选标记时,他们的反应
用户 ID 被添加到 'ppl hoo compleeted it' 下
在留言中。
user_reaction = await client.wait_for('reaction_add')
u = user_reaction.message.id
if user_reaction == '✅':
m = m.append(">>> " + u + "\n")
await msg.edit(m)
这是目前在 Discord 中的样子的图片:
screenshot_of_delyubjectivbot
因为 on_reaction_add
接受两个参数,所以它 return 是一个元组。 client.wait_for
中的 return 值反映了事件引用中的参数,见此处:https://discordpy.readthedocs.io/en/stable/api.html#discord-api-events
这个例子应该给你一个很好的起点:
reaction, user = await client.wait_for('reaction_add')
# Just access `user.id` for the id
if str(reaction.emoji) == '✅':
e = m.embeds[0]
e.description = f'{e.description}\n> {user}'
await m.edit(embed=e)
不清楚 msg
在您的代码中的含义。它看起来像一个 str
,但你也调用了 msg.edit
,它只适用于 discord.Message
对象。
更新:
async def on_message(m):
# put your msg content and etc here
def check(reaction, user):
return m.id == reaction.message.id and str(reaction.emoji) == '✅'
description = m.embeds[0].description
while not client.is_closed():
try:
reaction, user = await client.wait_for('reaction_add', check=check, timeout=35)
except asyncio.TimeoutError:
break
else:
e = m.embeds[0]
description += f'\n> {user.mention}'
e.description = description
await m.edit(embed=e)
我刚拿起 python 并在互联网、discord py API 和 Whosebug 上进行了一些搜索,但我仍然不确定如何让我的 discord 机器人正常工作。
当用户对机器人嵌入消息上的复选标记做出反应时,是否有办法获取不和谐用户 ID?
这是我的代码: 这部分有效:
#new dely ubjectiv
if msg.startswith('$new_dobj'):
ubj = msg.replace('$new_dobj ','')
embed = discord.Embed(title = "Dely Ubjectiv:", description = ubj +"\n\n**ppl hoo compleeted it:**", colour = 0x99dfff)
m = await message.channel.send(embed=embed)
await m.add_reaction('✅')
下面的代码似乎没有做任何事情。目标:当人们点击复选标记时,他们的反应 用户 ID 被添加到 'ppl hoo compleeted it' 下 在留言中。
user_reaction = await client.wait_for('reaction_add') u = user_reaction.message.id if user_reaction == '✅': m = m.append(">>> " + u + "\n") await msg.edit(m)
这是目前在 Discord 中的样子的图片: screenshot_of_delyubjectivbot
因为 on_reaction_add
接受两个参数,所以它 return 是一个元组。 client.wait_for
中的 return 值反映了事件引用中的参数,见此处:https://discordpy.readthedocs.io/en/stable/api.html#discord-api-events
这个例子应该给你一个很好的起点:
reaction, user = await client.wait_for('reaction_add')
# Just access `user.id` for the id
if str(reaction.emoji) == '✅':
e = m.embeds[0]
e.description = f'{e.description}\n> {user}'
await m.edit(embed=e)
不清楚 msg
在您的代码中的含义。它看起来像一个 str
,但你也调用了 msg.edit
,它只适用于 discord.Message
对象。
更新:
async def on_message(m):
# put your msg content and etc here
def check(reaction, user):
return m.id == reaction.message.id and str(reaction.emoji) == '✅'
description = m.embeds[0].description
while not client.is_closed():
try:
reaction, user = await client.wait_for('reaction_add', check=check, timeout=35)
except asyncio.TimeoutError:
break
else:
e = m.embeds[0]
description += f'\n> {user.mention}'
e.description = description
await m.edit(embed=e)