【问题标题】:How to dm person who used command in discord如何在不和谐中对使用命令的人进行 dm
【发布时间】:2017-11-13 19:51:31
【问题描述】:

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

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

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

【问题讨论】:

  • 你的代码有什么问题?它有什么作用?您的预期结果与实际结果是什么?你有任何错误吗?你试过什么?
  • 抱歉没有详细说明,我的代码应该做的是当有人这样做时(这是一个例子)!测试然后他们会收到一条直接消息说些什么。当我尝试这个时,它告诉我: NameError: name 'message' is not defined。我不知道该怎么办。
  • 也许尝试搜索您的错误代码? discord.py send_message ussage 的可能重复项
  • 试过了,可能有效,但现在没有定义名称'send_message'。

标签: python discord


【解决方案1】:
 @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

【讨论】:

    猜你喜欢
    • 2018-07-21
    • 2020-08-26
    • 1970-01-01
    • 2022-01-23
    • 2019-03-09
    • 1970-01-01
    • 2018-11-10
    • 2020-11-05
    相关资源
    最近更新 更多