python - 如何让我的不和谐机器人在 Python 中读取 dms?
问题描述
我有一个不和谐的机器人,它工作正常,我只有一个问题:如果机器人由于某些命令向某人发送 DM,我希望它接收到该 DM 的答案。我不明白它对 DM 有用。我尝试了一些我在互联网上找到的东西,但没有任何东西接近工作。任何帮助将不胜感激:)这是我尝试过的(对不起,我不能给你那么多)
@bot.event
async def on_private_message(ctx):
if ctx.channel.id == ctx.author.dm_channel.id:
# here I've tried using ctx.content in several ways but there was no ctx.content...
解决方案
on_private_message
不是不和谐事件,我们只是使用on_message
并检查它是否是 dm。
@bot.event()
async def on_message(message):
if message.guild is None:
#this is a dm message
但是,我看到您的问题是在私人消息中接受用户的回答,这可以通过wait_for
.
@bot.command()
async def something(ctx):
await ctx.author.send('hello there')
await ctx.author.send("you have 30 seconds to reply")
msg = bot.wait_for('message', check = lambda x: x.author == ctx.author and x.channel == ctx.author.dm_channel, timeout=30)
# do stuff with msg
参考:
推荐阅读
- sql - 来自 FUNCTION args 的 PostgreSQL SET 配置
- java - 如何从 GDrive 恢复文件?
- google-app-engine - 如何使用 Google Cloud Tasks 扩展拉取队列
- multithreading - 工作池模式 - 死锁
- c# - Azure DevOps VssConnection - 如何判断服务器是托管还是本地?
- python - 添加具有潜在 kwarg 问题的 Soap Zeep Header
- android - 重新创建活动时,底部工作表保持在屏幕上
- python - 如何使用 URL regexp 匹配 Django 中帖子的确切日期?
- java - 导出 JAR 文件中的图像
- excel - 在输入框中保留多个条目