Search code examples
pythondiscorddiscord.py

discord.py - How do I accept both no arguments and one argument?


I'm trying to code an economy bot and the beg command requires either no argument or one argument, which should be a user mention object. How can I accept a command such as: sov bal and sov bal @user? I've tried passing *args through in the secondary argument (i.e. x(*args)), and it did not work. Any help would be appreciated.


Solution

  • def foo(bar=None):
        if (str(bar)!="None"):
            bar = "default stuff"
    

    You don’t need str(bar)!="None".
    I have OCD and my coding is highly affected by it.

    Credits to DrummerMann!!!