【问题标题】:A command for discord bot to say server amd channel name让不和谐机器人说出服务器和频道名称的命令
【发布时间】:2020-11-07 04:39:54
【问题描述】:

我需要{server}{channel} 方面的帮助。我不能让机器人说出服务器名称和频道名称。

@client.command()
async def whereami(ctx):
    await ctx.send(f'You are on {server} on {channel}')

【问题讨论】:

    标签: python pycharm discord bots mention


    【解决方案1】:

    未定义服务器和通道。 ctx 参数是一个对象,它具有您正在寻找的两个属性;公会和频道(公会是他们在 Discord 中的名称,而不是服务器)。因此,通过使用 ctx.channel 和 ctx.guild,您可以访问公会和频道对象。

    @client.command()
    async def whereami(ctx):
       await ctx.send(f'You are on {ctx.guild} on {ctx.channel}')
    

    您可以在官方文档中阅读有关所有属性的更多信息: discord.py docs

    【讨论】:

      猜你喜欢
      • 2021-08-13
      • 2023-04-05
      • 2021-03-14
      • 2020-12-28
      • 2019-06-24
      • 2021-11-01
      • 2021-08-26
      • 2021-08-05
      • 2018-11-10
      相关资源
      最近更新 更多