diff --git a/bot.py b/bot.py index a3e6745..fb79485 100755 --- a/bot.py +++ b/bot.py @@ -64,7 +64,7 @@ class Bot(Bot): user_id_md5 = hashlib.md5(ctx.author.id.to_bytes(8, byteorder='big'), usedforsecurity=False).digest() await self.pool.execute( 'INSERT INTO invokes (guild_id, user_id_md5, command) VALUES ($1, $2, $3)', - ctx.guild.id, user_id_md5, ctx.command.qualified_name, + getattr(ctx.guild, 'id', None), user_id_md5, ctx.command.qualified_name, ) # we use on_shard_ready rather than on_ready because the latter is a bit less reliable diff --git a/schema.sql b/schema.sql index 363b4ed..ce00388 100644 --- a/schema.sql +++ b/schema.sql @@ -2,7 +2,8 @@ SET TIME ZONE 'UTC'; -- inserted for every time a command is invoked CREATE TABLE invokes ( - guild_id BIGINT NOT NULL, + -- nullable because it may be invoked in DMs + guild_id BIGINT, -- hashed for privacy user_id_md5 BYTEA NOT NULL, -- the qualified name of the command invoked (https://discordpy.readthedocs.io/en/stable/ext/commands/api.html?highlight=qualified_name#discord.ext.commands.Command.qualified_name)