I’m working on a Discord bot and I want to track which user runs specific commands. Right now my logging function just says “someone” but I need it to show the actual username.
Both solutions work, but manual tracking becomes a nightmare once you’re running bots across multiple servers. Trust me - I’ve been there.
Skip the logging fixes and automate everything instead. Build a workflow that captures command executions, dumps them into a database, and alerts you when something’s up.
But honestly? Automate the whole thing. Hook into your Discord bot events, log everything to a real database, generate daily reports, and get notifications when specific users run certain commands.
No more copying logging code everywhere. No more lost data after restarts. Just clean automation handling user tracking, command analytics, and monitoring while you focus on other stuff.
This saved me hours of debugging and gave way better insights into how people actually use my bots.
You’re passing the wrong parameters to LogCommand. Instead of self.LogCommand(self, "hello"), you need to pass the context object - that’s where all the user info lives.
Also, you might want to use ctx.author.global_name instead of ctx.author.name. Discord’s been moving away from discriminators, and global_name shows the actual display name users see - way better for logging.
The context object has everything you need about who ran the command. Don’t hardcode ‘someone’ - just grab the user data from ctx.author. Here’s what I use:
I add the discriminator because Discord usernames aren’t unique. You can also use ctx.author.id if you need the unique user ID for database stuff or better tracking.
I’ve run Discord bots for years and always throw ctx.guild.name into my logs too - super handy when you’re running across multiple servers. The ctx object has all the metadata you need about where and how the command was triggered.
you’ve got an extra self parameter in your LogCommand call. change self.LogCommand(self, "hello") to self.LogCommand(ctx, "hello"). also make sure your function signature accepts ctx like the other examples.
Everyone’s fixing the syntax, but you’re missing the bigger picture. Once your bot grows beyond a few commands, you’ll copy-paste that LogCommand call everywhere.
But think ahead. Want command usage stats? User analytics? Rate limiting per user? Error tracking?
I learned this running bots for thousands of users - manual logging becomes a nightmare.
Build an automation workflow that captures every Discord event, processes the data, stores it properly, and gives you dashboards without touching your bot code. Hook into Discord’s API events and let automation handle user tracking, command analytics, and monitoring.
Your bot stays clean. Data stays consistent. You get way better insights than print statements.
To retrieve the username of the user who executed a command, pass the ctx variable to your logging function. Modify your LogCommand method to accept ctx as a parameter and fetch the username like this:
Using ctx.author allows you to access the user’s details. If you prefer, you can use ctx.author.display_name for their display name. Remember to remove the extra self in the LogCommand call to avoid issues.