【问题标题】:Sending a DM to a specific user向特定用户发送 DM
【发布时间】:2021-02-24 14:16:46
【问题描述】:

你好

我想做什么

您好,我正在尝试向触发以下功能的用户发送 DM:

    if message.content.startswith("!help"):
        await message.author.send("hello")

在用户将 !help 发送到任何不和谐的服务器频道后,我希望机器人向用户发送消息 Hello as a DM

问题

我没有收到任何错误,如果我在聊天中输入 !help 就什么也没有发生

我是初学者,所以我很高兴能得到所有帮助 =)

【问题讨论】:

  • 我试过@client.event @bot.command @client.event.,函数是async def on_message(message):

标签: python function discord discord.py dm


【解决方案1】:

你不应该使用 on_message 来检查这样的事情。您应该将其作为命令处理。

假设您已正确设置命令...

import discord

from discord.ext import commands

client = commands.Bot(command_prefix=";")
client.remove_command('help')

...

@client.command()
async def help(ctx):
    await ctx.author.send("something")

...

【讨论】:

  • 如果我尝试使用@client.command,它会显示类“client”的未解析属性引用“command”
猜你喜欢
  • 2021-12-24
  • 2021-04-26
  • 2021-01-06
  • 2021-12-29
  • 1970-01-01
  • 2021-12-23
  • 1970-01-01
  • 2020-07-28
  • 1970-01-01
相关资源
最近更新 更多