如何在不和谐中使用命令的人

时间:2017-11-02 17:56:12

标签: python discord

这是我执行命令的人的代码:

 @client.command()
 async def test(pass_context=True):
     await message.author.sendMessage("test")

我的代码应该做的是当有人做(这是一个例子)!测试然后他们会收到一条直接消息说些什么。当我尝试这个时它告诉我:NameError:没有定义名称'message'。我不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

 @client.command(pass_context=True)
 async def test(ctx):
     await client.send_message(ctx.message.author, "test")

您正在传递上下文,您可以使用该上下文直接发送给邮件的作者。

您还在错误的地方使用pass_context=True,它需要在创建命令的位置,而不是定义

(即ctx.message.authorctx.message.channel

相关问题