【发布时间】: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
我需要{server} 和{channel} 方面的帮助。我不能让机器人说出服务器名称和频道名称。
@client.command()
async def whereami(ctx):
await ctx.send(f'You are on {server} on {channel}')
【问题讨论】:
标签: python pycharm discord bots mention
未定义服务器和通道。 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
【讨论】: