有什么办法可以得到公会对象的一个​​命令是运行吗?

Is there any way to get the guild object a command is run it?

我希望我的机器人 运行 在不同的公会中,有时,我需要一个公会对象来获取公会的不同成员。我已经看到一些答案使用 bot.guilds 来获取 all 机器人所在的公会,但我该如何获取它输出命令在 运行?

中的公会对象

到目前为止,这是我的代码:

from discord.ext import commands, tasks
import discord
intents = discord.Intents.all
bot = commands.Bot(command_prefix='$', description='- shows this message', intents=intents)
---- snip ----
@bot.command()
async def get_guild(ctx):
    pass

bot.run('TOKEN')

传递给命令的 ctxinvocation context。它有一个属性 ctx.guild,它将是代表调用命令的公会的 discord.Guild 对象(或者 None 如果它是在私人频道中调用的)