首页 > 解决方案 > 向特定用户发送 DM

问题描述

你好

我想做的事

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

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

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

问题

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

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

标签: pythonfunctiondiscorddiscord.pydm

解决方案


你不应该使用 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")

...

推荐阅读