【问题标题】:How do i mention a member when they say a certain command?当他们说出某个命令时,我如何提及成员?
【发布时间】:2020-07-07 21:27:27
【问题描述】:

我正试图让机器人说“嘿(用户)这里是 hxd 的下载链接”有人可以帮助我吗?

async def hxd(ctx):
  await client.say('Here is a download link for hxd')

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    每个discord.Member 对象都有一个mention 属性。
    以下是您的使用方法:

    @client.command()
    async def hxd(ctx):
      await client.say(f"Hey {ctx.author.mention}! Here's a download link for hxd")
    

    【讨论】:

    • 你也可以使用稍短的ctx.author.mention
    【解决方案2】:

    你可以使用getpass.getuser():

    from getpass import getuser
    async def hxd(ctx):
      await client.say(f'Hey {getuser()} here is a download link for hxd')
    

    【讨论】:

    • 我收到此错误:prnt.sc/tdeyik 这些是我的导入:prnt.sc/tdez5m
    • @GrenadeVisuals 只是import getpass,而不是from os import getpass
    • 当您只需要使用mention 属性时,为什么还要使用getpass
    • @Mr_Spaar 另外,getuser 属性有什么问题?
    • 由于这个问题有discord.py标签,他可以使用mention属性,所以他只需要导入一个库,即discord.py^^
    猜你喜欢
    • 2020-11-01
    • 2019-03-18
    • 2021-09-05
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多