Search code examples
pythondiscorddiscord.pybotschatbot

Discord Bot Python message logs


Hi so I need to create a discord bot in python that stores a specific users sent messages in a seperate channels. Basically like message logs but its just for one user and every message they sent deleted or not If anyone could show me how to do that it would mean ALOT


Solution

  • While I agree with Elitezen's comment, the answer is quite simple.

    
    import discord
    from discord.ext import commands
    
    client = commands.Bot(command_prefix=<YOUR PREFIX>)
    
    @client.event
    async def on_message(message):
        if message.author.id == <ID OF USER>:
            with open("log.txt","a") as f:
                f.write(message.content + "\n")
    
    client.run(TOKEN)