如何使我的不和谐机器人在Python中读取dms? [英] How do I make my discord bot reading dms in Python?
问题描述
我有一个不和谐的机器人,它工作正常,但我有一个问题:如果该机器人由于某条命令向某人发送了DM,我希望它收到该DM的答案.我不了解它对DM的作用.我已经尝试了一些我在互联网上找到的东西,但是没有什么比这更有效了.任何帮助将非常感激 :)这是我尝试过的方法(对不起,我不能给你那么多)
I have got a discord bot and it works fine, I've just got one problem: If the bot sends a DM to someone due to some command, I want it to receive the answer to that DM. I don't get it working for DMs. I've tried some stuff I've found on the internet but nothing was even close to working. Any help would be much appreciated :) Here's what I've tried (I'm sorry I can't give you that much)
@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.
on_private_message
is not a discord event, we just use on_message
and check if it is a dm.
@bot.event()
async def on_message(message):
if message.guild is None:
#this is a dm message
但是,我看到您的问题是在私人消息中接受用户的答复,这可以通过 wait_for
完成.
However, I see that your problem is accepting an answer from a user in private message, this can be done with 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
参考文献:
- dm_channel
- 参考我以前的答案以获取有关
wait_for
的信息
这篇关于如何使我的不和谐机器人在Python中读取dms?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!