How can i fix this pycord code project i made?

Question:

I have a discord bot project. In the following code I made that if you reply a specific word the bot will give you a role. I already created the role but when I try it turn out to a error.

I’m using Pycord.

Code:

@bot.slash_command()
async def money(ctx):
    await ctx.send("How much money you have?")

    def check(m):
        return m.content == "100,000" and m.author == ctx.author

    role_input = await bot.wait_for('message', check=check)
    role = discord.utils.get(ctx.guild.roles, name="Rich")
    await role_input.author.add_roles(role)
    await ctx.send(f"{role_input.author.mention}, you have been given the 'Rich' role.")

I was trying to make a slash command that the bot will reply "How much money you have?" and if you reply the specific word "100,000" then the bot will grant you a role.

Asked By: 34-4

||

Answers:

The reason you’re getting "the application did not respond" is because you’re never responding to the application command. As your command could probably take a while waiting for the user to respond, we can use await ctx.defer() to defer our response and then use await ctx.followup.send to send the followup message and respond. If you didn’t use defer, you could also use ctx.response.send_message or ctx.respond in cases where the command doesn’t take too long to execute.

@bot.slash_command()
async def money(ctx):
    # deferring as it might take us a while
    await ctx.defer()

    await ctx.send("How much money you have?")

    def check(m):
        return m.content == "100,000" and m.author == ctx.author

    role_input = await bot.wait_for('message', check=check)
    role = discord.utils.get(ctx.guild.roles, name="Rich")
    await role_input.author.add_roles(role)
    await ctx.followup.send(f"{role_input.author.mention}, you have been given the 'Rich' role.")
Answered By: ESloman
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.