我对不协调编程感到困惑的唯一部分是什么上下文?从消息中获取上下文时,上下文实际上可以访问什么。在我的一个嵌齿轮中,我有此命令test
。
@commands.command()
async def test(self, ctx):
await ctx.send("Hello world!")
里面有什么ctx
?例如,如果我想访问该Message
对象,则可以通过来获得ctx.message
。我知道通过谷歌搜索一堆。在上下文中还有什么其他东西?为此有某种UML图吗?我想知道如何获取guild
对象或member
对象。文档中列出的几乎所有Discord模型。
作为Lu M的答案,作为获取对象属性的“笨拙”方法,您始终可以运行:
print(dir(ctx)) # or replace ctx with whatever object's attributes you are trying to find
# equivalent:
print(dir(type(ctx))) # once again, replacing ctx with any other object you might try to find
这将返回对象可以使用的每个属性的列表。
但是,最好在可用时使用文档。使用它作为“最后的手段”或“懒惰的方法”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句