how do you convert a python code that requires user input to work in a discord bot?

后端 未结 2 933
自闭症患者
自闭症患者 2021-01-16 17:55

So I have a piece of code and it requires user input multiple times (and what is inputed is not alway the same). Instead of passing the code to everyone in my discord I woul

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-16 18:38

    Using wait_for

    async def botcalc(self, ctx):
            author = ctx.author
            numbers = []
    
            def check(m):
                return m.author ==  author
    
            for _ in ('first', 'second'):
                await ctx.send(f"enter {_} number")
                num = ""
                while not num.isdigit():
                    num = await client.wait_for('message', check=check)
                numbers.append[int(num)]
    
            await channel.send(f'{numbers[0]}+{numbers[1]}={sum{numbers)}')
    

    edit

    Added a check

提交回复
热议问题