if-name-main
This is a statement that is only true if the module (your source code) it appears in is being run directly, as opposed to being imported into another module. When you run your module, the __name__
special variable is automatically set to the string '__main__'
. Conversely, when you import that same module into a different one, and run that, __name__
is instead set to the filename of your module minus the .py
extension.
on-message-event
Registering the on_message
event with @bot.event
will override the default behavior of the event. This may cause prefix commands to stop working, because they rely on the default on_message
event handler.
Instead, use @bot.listen
to add a listener. Listeners get added alongside the default