如何使我的不和谐机器人在Python中读取dms? [英] How do I make my discord bot reading dms in Python?

查看:77
本文介绍了如何使我的不和谐机器人在Python中读取dms?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不和谐的机器人,它工作正常,但我有一个问题:如果该机器人由于某条命令向某人发送了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

参考文献:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆