从DM中的答复中获取消息内容 [英] Get message content from reply in DM

查看:85
本文介绍了从DM中的答复中获取消息内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始制作一个不和谐的小机器人,将钥匙提供给要求它的人。但是,要求已更改,现在我需要收到想要的人的有效电子邮件。我不确定如何在DM中获得回复。

I started making a little discord bot to give a key to people who request it. However, requirements changed and now I need to get a valid email from people who want one. I'm not sure how to get a reply in a DM.

我看到了 Discord.py从DM获取消息

但是我真的没有client.get_user_info()之类的东西吗?

But I don't really have client.get_user_info() or something?

bot = commands.Bot(command_prefix='!')


@bot.command(pass_context =True, no_pm=True, name='key', help="I give you a key. you're welcome", )



async def key_giver(ctx):
    commandTime = str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))


##check if you're PMing bot
    elif isinstance (ctx.channel, discord.DMChannel):
        print(ctx.message)
        await ctx.author.send(keyArray[0])

    else:
        response = "Hello my friend. I give you a key for a game. This is my purpose. Please enter your email!"



    ##Send key via PM 
    await ctx.author.send(response)



打印ctx.message是

Printing ctx.message is

<消息id = 620538695124254720频道=< DMChannel id = 614377525417738240收件人=<用户id = 605223566371192852名称='aon'鉴别器='5906'bot = False> type =< MessageType.default:0> author =<用户id = 605223566371192852 name ='aon'discriminator ='5906'bot = False>>

我真的不确定。我只是愚蠢,请不要对我大喊。

I'm really not sure. I'm just stupid, please don't yell at me.

推荐答案

您可以使用 Client.wait_for 等待消息并使用其结果。您已经有了 User 对象( ctx.author ),因此您可以从 User.dm_channel 。我正在重新使用以前的答案中的 message_check 函数生成支票

You can use Client.wait_for to wait for the message and use its results. You already have the User object (ctx.author), so you can get the channel to listen for from User.dm_channel. I'm re-using the message_check function from this previous answer to generate the check

# Send them a message in a DM
await ctx.author.send("Please give an email address")

# Wait for a response
response = await bot.wait_for('message', check=message_check(channel=ctx.author.dm_channel))

这篇关于从DM中的答复中获取消息内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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