Ask coding questions

← Back to all posts
I can't fix this type of error even I fix the indent in notepad
mooping9383 (0)

So here's my problem
I made the discord.py bot BUT I want it to say error when user type string instead of integer

@commands.command(name='volume')
    async def _volume(self, ctx: commands.Context, *, volume: int):
		

        """Sets the volume of the player."""

        if not ctx.voice_state.is_playing:
            return await ctx.send('Nothing being played at the moment.')
		if isinstance(volume,str):
	return await ctx.send(f"Give me only number not {volume} >:( \nStupid this man don't know which is number which is word")
        if 0 > volume > 100:
            return await ctx.send('Volume must be between 0 and 100')

        ctx.voice_state.volume = volume / 100
        await ctx.send('Volume of the player set to {}%'.format(volume))

And this line have problem

if isinstance(volume,str):
	return await ctx.send(f"Give me only number not {volume}

I can't fix it with notepad,arrange it again,write same thing back.

Answered by RYANTADIPARTHI (6009) [earned 5 cycles]
View Answer
Comments
hotnewtop
RYANTADIPARTHI (6009)

you can just use int() for wherever you want the user to type.

mooping9383 (0)

@RYANTADIPARTHI Tried that before..
I guess you want me to do this right?

@commands.command(name='volume')
    async def _volume(self, ctx: commands.Context, *, volume):
          if volume != int:
             await ctx.send("No word please. :3\nPlease.")
		
RYANTADIPARTHI (6009)

@mooping9383 no. don't indent the async line.