繁体   English   中英

Discord.py 如何让下一个用户的留言成为一个变量?

[英]Discord.py How to make next user's message a variable?

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix = "{")

1. @bot.command(pass_context = True)
2. async def hello(ctx): #I know that exactly this function can be made easier.
3.     ctx.send("Enter the name")
4.     #user's message without {hello
5.     ctx.send(f"Hello {#name from the previous line#}")

行注释: 2. 用户输入 {hello 3. Bot 发送消息(输入姓名) 4. 用户发送消息聊天时没有 {hello,所以只有名字 5. Bot 发送消息(你好,{name} )

用什么代替第 4 行和第 5 行的一部分?

https://discordpy.readthedocs.io/en/latest/api.html#discord.Client.wait_for

@client.event
async def on_message(message):
    if message.content.startswith('$greet'):
        channel = message.channel
        await channel.send('Say hello!')

        def check(m):
            return m.content == 'hello' and m.channel == channel

        msg = await client.wait_for('message', check=check)
        await channel.send('Hello {.author}!'.format(msg))

您需要一个check()方法,以便获得正确的消息 object。在检查中,您定义消息 object 在什么条件下是正确的。 在您的情况下,退货应更改为:

return m.author == message.author and m.channel == message.channel

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM