python - 向特定用户发送 DM
问题描述
你好
我想做的事
您好,我正在尝试向触发以下功能的用户发送 DM:
if message.content.startswith("!help"):
await message.author.send("hello")
在用户将 !help 发送到任何不和谐的服务器频道后,我希望机器人向用户发送消息 Hello as a DM
问题
我没有收到任何错误,如果我在聊天中输入 !help,就什么也没有发生
我是初学者,所以我很高兴能得到所有帮助 =)
解决方案
你不应该使用 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")
...
推荐阅读
- css - 带颜色抠像的灰度图像
- bash - DevOps 管道:git 命令“git symbolic-ref --short -q HEAD”似乎不再起作用
- javascript - 更改状态后如何禁用按钮接受和拒绝?
- java - 无法在 Eclipse 2021-03 上运行 JUnit 5 测试
- c# - 为什么我的受 AAD 保护的 Azure 函数在使用来自 UWP 应用的访问令牌调用时返回 401?
- redis - 我们不能用 RDBMS 模拟 nosql 键值对数据库吗
- html - 缩小屏幕时显示绝对中的表格没有完全出现?
- flutter - 提供不同的构建配置/风格(开发、生产)
- powerbi - 在需要单个值的地方提供了一个包含多个值的表 - 将它们连接起来
- blender - 网格在虚幻引擎中不反射光