@@ -29,7 +29,7 @@ async def on_raw_reaction_add(payload):
2929 message = await channel .fetch_message (payload .message_id )
3030
3131 # Create a new inbox item using async
32- item = InboxItem (
32+ await InboxItem . objects . acreate (
3333 message_id = str (message .id ),
3434 channel_id = str (payload .channel_id ),
3535 channel_name = f"#{ channel .name } " ,
@@ -38,7 +38,6 @@ async def on_raw_reaction_add(payload):
3838 author = str (message .author .name ),
3939 content = message .content ,
4040 )
41- await item .asave ()
4241
4342
4443@bot .event
@@ -55,17 +54,27 @@ async def on_raw_reaction_remove(payload):
5554
5655@bot .command ()
5756async def inbox (ctx ):
58- """Display a user's inbox items"""
57+ """
58+ Displays the content of the inbox for the user that calls the command.
59+
60+ Each message is saved with user_id (which is a discord id), and here we can
61+ filter out all those messages depending on who called the command.
62+
63+ It retuns all tracked messages, starting from the one most recently saved
64+ (a message that was most recently tagged with inbox emoji, not the message
65+ that was most recently sent).
66+ """
5967 user_id = str (ctx .message .author .id )
6068 inbox_items = InboxItem .objects .filter (user_id = user_id ).order_by ("-created_at" )
6169
62- msg = "Currently tracking the following messages:\n "
6370
6471 # Use async query
6572 if not await inbox_items .aexists ():
6673 await ctx .send ("Your inbox is empty." )
6774 return
6875
76+ msg = "Currently tracking the following messages:\n "
77+
6978 async for item in inbox_items :
7079 msg += "* " + item .summary () + "\n "
7180
0 commit comments