0

档案:78573462558784356

#这是一个id

异步定义:

@bot.event
async def on_raw_reaction_add(payload):
    with open("createteam.txt", "r", encoding = "utf-8") as file: # id is in a file
        author_id = file.read() #the id in str()
        author_user = ???author_id.User??? #how to translate a str(id) to discord.user
        author_member = ???author_id.Member??? #how to translate a str(id) to discord.member
4

2 回答 2

0

您可以discord.utils.get()用于获取用户。

@bot.event
async def on_raw_reaction_add(payload):
    with open("createteam.txt", "r", encoding = "utf-8") as file:
        author_id = file.read()
    member = discord.utils.get(payload.message.guild.members, id=int(author_id)) 

因此,您可以使用member.

于 2020-09-28T10:36:44.640 回答
0

1 你只需要一个用户的ID。

2 如果需要获取变量discord.User,则使用bot.get_user(id)。

3 如果需要获取变量discord.Member,则使用message.guild.get_member(id)。

其中 message.guild 是发送消息的服务器

PS 每次需要将 str() int() 或其他东西翻译成机器人可以读取的变量时,都需要使用 bot.get_ 或 guild.get_。都有get_:https ://discordpy.readthedocs.io/en/latest/search.html?q=get_&check_keywords=yes&area=default

于 2020-09-28T10:15:11.453 回答