简体   繁体   中英

How do i check if a user wrote the command?

I have this

await ctx.send("Which inventory do you want to access?")
        await ctx.send("Mining, Collecting, Farming, Fishing or Fighting?")

        def check(user):
            if user == ctx.author:
                # Idk what to do here
                pass

        type_check = await self.bot.wait_for('message', check=check)

        if type_check.content.lower() == "mining":
            await ctx.send("You chose Mining!")

        if type_check.content.lower() == "collecting":
            await ctx.send("You chose Collecting!")

        if type_check.content.lower() == "farming":
            await ctx.send("You chose Farming!")

        if type_check.content.lower() == "fishing":
            await ctx.send("You chose Fishing!")

        if type_check.content.lower() == "fighting":
            await ctx.send("You chose Fighting!")

And I need to check if a user wrote the message and if they did it would await ctx send the thing

The check func must return a boolean, also the argument passed is a discord.Message object not a user

def check(message):
    if message.author == ctx.author:
        return True

or

# This is a better way
def check(message):
    return message.author == ctx.author

btw a better solution for those if statements is checking if they're in a list:

inv_type = type_check.content.lower()
if inv_type in ['mining', 'collecting', 'farming', 'fishing', 'fighting']:
    await ctx.send(f"You chose {inv_type}!")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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