Search code examples
pythonpython-3.xdiscorddiscord.pybots

i added a log feature for my discord bot and all of the commands don't work


I added a log feature for my discord bot and after that all of the commands started not to work

this is the code that i added:

@client.event
async def on_message(message, ctx):
    ts = time.time()
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
    with open("logs.txt", "a") as text_file:
        print(f"<{st}> <{message.author}> <{message.id}>  {message.content}", file=text_file)

Solution

  • Why does on_message make my commands stop working? https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working

    Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message.

    Consider using a listener. In a listener setup you do not need to manually call process_commands()

    Listener documentation: https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot.listen

    Examples are provided in both documentation links.