From 5c0453c71ab51b95e0ead26d94169b29829fdf9c Mon Sep 17 00:00:00 2001 From: mohammed masud Date: Thu, 19 Nov 2020 13:00:53 +0000 Subject: [PATCH] Replaced code with discord embed objects on the vote count bit --- Chatbot.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index 15319a8..5388b91 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -82,12 +82,10 @@ async def on_message(message): #checks for a message await message.channel.send(response) # ================================================ # ================ Masud did this ================ - - tickEmoji = "\u2705" # unicode for the tick Emoji - crossEmoji = "\u274C" # unicode for the cross Emoji - if "salt " == (message.content.lower())[:5]: # checks if the input matches "salt " communityName = (message.content)[5:] # saves the rest of the input as communityName + tickEmoji = "\u2705" # unicode for the tick Emoji + crossEmoji = "\u274C" # unicode for the cross Emoji if communityName.upper() in polls.values(): # if there is a poll active already pollID = list(polls.keys())[list(polls.values()).index(communityName.upper())] # get the ID of the poll @@ -100,7 +98,7 @@ async def on_message(message): #checks for a message await poll.add_reaction(tickEmoji) # add the tick emoji for the poll await poll.add_reaction(crossEmoji) # add the cross emoji for the poll - if "count " == (message.content.lower())[:6]: # cecks if the input matches "count " + if "count " == (message.content.lower())[:6]: # checks if the input matches "count " communityName = (message.content)[6:] # saves the rest of the input as communityName if communityName.upper() not in polls.values(): # checks if the poll does not exist already @@ -112,12 +110,19 @@ async def on_message(message): #checks for a message pollReactions = pollMessage.reactions # accesses the reactions for the pollMessage object await message.channel.send(f'Here are the saltiness statistics for the community {communityName}\nPoll ID:{pollID}') # message to discord + + countEmbed = discord.Embed() # Discord embed object + countDesc = "" # description of countEmbed object + countEmbed.title = f"Is the community {communityName} toxic?" # title of countEmbed object + for emj in pollReactions: # for each emoji in the reactions object - emojiCount = emj.count - 1 # remove 1 vote, which was from the bot. - if emojiCount == 1: # message to discord accordingly - await message.channel.send(f'{emj.emoji} : {emojiCount} vote') + emojiCount = emj.count - 1 # remove 1 vote, which was from the bot. + if emojiCount == 1: # adjust embed description accordingly + countDesc = countDesc + f'\n{emj.emoji} : {emojiCount} vote' else: - await message.channel.send(f'{emj.emoji} : {emojiCount} votes') + countDesc = countDesc + f'\n{emj.emoji} : {emojiCount} votes' + countEmbed.description = countDesc # add embed description to embed + await message.channel.send(embed=countEmbed) # send the embed to the channel the message is in # ================ up to about here ================