recently I've made a discord bot reminder command and got an issue with it, but thanks to Nurqm's help I was able to fix it. However, I got another issue in the time setting, when I do /reminder 5days Fix the server
, which is a reminder to remind me to fix the server after 5 days, I get a ValueError.
This is my code:
@client.command(case_insensitive = True, aliases = ["remind", "remindme", "remind_me"])
@commands.bot_has_permissions(attach_files = True, embed_links = True)
async def reminder(ctx, time, *, reminder):
print(time)
print(reminder)
user = ctx.message.author
embed = discord.Embed(color=0x55a7f7, timestamp=datetime.utcnow())
embed.set_footer(text="If you have any questions, suggestions or bug reports, please join our support Discord Server: link hidden", icon_url=f"{client.user.avatar_url}")
seconds = 0
if reminder is None:
embed.add_field(name='Warning', value='Please specify what do you want me to remind you about.') # Error message
if time.lower().endswith("days"):
seconds += int(time[:-4]) * 60 * 60 * 24
counter = f"{seconds // 60 // 60 // 24} days"
if time.lower().endswith("h"):
seconds += int(time[:-1]) * 60 * 60
counter = f"{seconds // 60 // 60} hours"
elif time.lower().endswith("m"):
seconds += int(time[:-1]) * 60
counter = f"{seconds // 60} minutes"
elif time.lower().endswith("s"):
seconds += int(time[:-1])
counter = f"{seconds} seconds"
if seconds == 0:
embed.add_field(name='Warning',
value='Please specify a proper duration, send reminder_help for more information.')
elif seconds < 300:
embed.add_field(name='Warning',
value='You have specified a too short duration!\nMinimum duration is 5 minutes.')
elif seconds > 7776000:
embed.add_field(name='Warning', value='You have specified a too long duration!\nMaximum duration is 90 days.')
else:
await ctx.send(f"Alright, I will remind you about {reminder} in {counter}.")
await asyncio.sleep(seconds)
await ctx.send(f"Hi, you asked me to remind you about {reminder} {counter} ago.")
return
await ctx.send(embed=embed)
The error is: Command raised an exception: ValueError: invalid literal for int() with base 10: '5day'
If anyone knows any information about how to deal with this error please inform me. Thanks in advance.
I just figured why that doesn't work, because you create a if statement
every time so when you type /reminder 10days test
, it triggers days but also triggers elif time.lower().endswith("s"):
. If you change this if time.lower().endswith("h"):
if statement
to elif statement
, your problem will be solved.
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.