discord.py提醒命令问题求助:参数显示异常与缺失无提示
Fixing Your Discord Bot's Reminder Command Issues
Let's break down the two main problems in your code and fix them step by step:
1. Incorrect Parameter Handling (Reminder Content Shows as {})
Your current parameter setup *time, **reminder is the root cause here:
*timecaptures all positional arguments (including your reminder text likeFix,the,server), leaving**reminderas an empty dictionary (since users don't pass keyword arguments in Discord commands). That's why you see{}in your messages.- To fix this, we need to split the input into time components and the reminder text properly. We'll use
*argsto capture all input, then separate time parts (those ending withd/h/m/s) from the reminder content.
2. Failed Error Trigger for Missing Reminder
The check if reminder is None: never works because **reminder will always be an empty dictionary (not None) when no keyword arguments are provided. We need to check if we have any reminder content left after extracting time parts.
Modified Working Code
Here's the corrected version of your command with explanations:
import asyncio import datetime import discord from discord.ext import commands @bot.command(case_insensitive=True, aliases=["remind", "remindme", "remind_me"]) @commands.bot_has_permissions(attach_files=True, embed_links=True) async def reminder(ctx, *args): user = ctx.message.author # Predefine error embeds (unchanged from your code) embed = discord.Embed( title="Please specify a proper duration, send `reminder_help` for more information.", description="", 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"{bot.user.avatar_url}" ) embed2 = discord.Embed( title="Please specify what do you want me to remind you about.", description="", color=0x55a7f7, timestamp=datetime.utcnow() ) embed2.set_footer( text="If you have any questions, suggestions or bug reports, please join our support Discord Server: link hidden", icon_url=f"{bot.user.avatar_url}" ) embed3 = discord.Embed( title="You have specified a too long duration!\nMaximum duration is 90 days.", color=0x55a7f7, timestamp=datetime.utcnow() ) embed3.set_footer( text="If you have any questions, suggestions or bug reports, please join our support Discord Server: link hidden", icon_url=f"{bot.user.avatar_url}" ) embed4 = discord.Embed( title="You have specified a too short duration!\nMinimum duration is 5 minutes.", color=0x55a7f7, timestamp=datetime.utcnow() ) embed4.set_footer( text="If you have any questions, suggestions or bug reports, please join our support Discord Server: link hidden", icon_url=f"{bot.user.avatar_url}" ) seconds = 0 time_parts = [] reminder_parts = [] # Split args into time components and reminder text for arg in args: if arg.lower().endswith(("d", "h", "m", "s")): time_parts.append(arg) else: reminder_parts.append(arg) # Check if reminder is missing if not reminder_parts: await ctx.send(embed=embed2) return reminder_text = " ".join(reminder_parts) counter_parts = [] # Calculate total seconds and build counter text for part in time_parts: value = int(part[:-1]) unit = part[-1].lower() if unit == "d": seconds += value * 60 * 60 * 24 counter_parts.append(f"{value} days") elif unit == "h": seconds += value * 60 * 60 counter_parts.append(f"{value} hours") elif unit == "m": seconds += value * 60 counter_parts.append(f"{value} minutes") elif unit == "s": seconds += value counter_parts.append(f"{value} seconds") # Combine counter parts into a readable string (e.g., "1 day, 30 minutes") counter = ", ".join(counter_parts) if counter_parts else "" # Validate duration if seconds == 0: await ctx.send(embed=embed) return elif seconds < 300: await ctx.send(embed=embed4) return elif seconds > 7776000: await ctx.send(embed=embed3) return # Send confirmation and wait for reminder await ctx.send(f"Alright, I will remind you about {reminder_text} in {counter}.") await asyncio.sleep(seconds) await ctx.send(f"Hi, you asked me to remind you about {reminder_text} {counter} ago.")
Key Improvements:
- Proper Parameter Splitting: We now separate time components from the reminder text, so your reminder content will display correctly.
- Working Missing Reminder Check: We check if
reminder_partsis empty, which triggers the error embed correctly when no reminder text is provided. - Better Counter Display: The counter now supports multiple time units (e.g.,
1d 2hwill show as "1 days, 2 hours" instead of just the last unit). - Robust Time Parsing: Each time part is processed individually, avoiding overwriting the counter variable.
内容的提问来源于stack exchange,提问作者Libby




