关于 discord.py 的 send_file()

Regarding discord.py's send_file()

我一直在摆弄 discord.py 函数 send_file()。

我最初使用这个问题的答案来基本了解我需要的参数:

但是我计划在几台服务器上使用我的机器人,而不仅仅是一台,并且上面链接的问题中给出的答案基本上硬编码了一个特定的通道来发送文件。

我想做的是让我的机器人获取它在其中获得 !moe 命令的频道的 ID,并将文件发送到同一频道。

@client.command()
async def moe():

    await client.send_file(client.get_server('How do I get the ID of the discord channel that calls this command?')),'moe.gif')

假设您正在使用 rewrite 分支(iirc,您应该这样做),它就像将 ctx 参数用于命令函数和 accessing ctx.channel (请注意,文档示例似乎与它之前所说的相矛盾,但实际上它只是 shorthand)。如果您 不是 使用 rewrite 分支,我相信它应该是几乎相同的过程,但您的装饰器应该看起来像这样:

@client.command(pass_context=True)