Added a function to make bot send a message when mentioned - #15
Added a function to make bot send a message when mentioned#15pistonpro0001 wants to merge 10 commits into
Conversation
Used the `bot.event` decorator to allow bot to respond to replies and mentions, only when it isn't the bot itself. Also removed unneeded function `get_or_create...` because the game I made to test isn't implemented anymore. Closes: #14
| @bot.event | ||
| async def on_message(message): | ||
| if message.author == bot.user: | ||
| return |
There was a problem hiding this comment.
By PEP 8, it's a bad practice to do the implicit return of None, but, for now, we don't have an established style guidelines, so I'll keep the decision to the author.
Our main goal is to establish the style guidelines and then we can continue to make new changes and review PRs.
There was a problem hiding this comment.
Still implicit return of None
Co-authored-by: Roman <romanmashevskyi@proton.me>
roli2py suggested that I comment how the parts of the bot reply function work, so I added comments in the `on_message` function to clarify what each part of the function does.
Place the run to mitigate the problems when the tools are invoking the main module to inspect dependencies or get a `version` variable.
Add the guidelines to mitigate typical mistakes when making changes to the code and resolve the problems on this basis more easily.
| if message.reference: # Is the message a refrence to anyone (reply or mention)? | ||
| if message.reference.cached_message: # Does the bot already has the original message saved in its memory? | ||
| is_reply_to_bot = message.reference.cached_message.author == bot.user # Check if the message it replied to was from the bot | ||
| else: | ||
| try: | ||
| original_msg = await message.channel.fetch_message(message.reference.message_id) # Get the original message replied to | ||
| is_reply_to_bot = original_msg.author == bot.user # Check if the message it replied to was from the bot |
There was a problem hiding this comment.
Comments are so concrete and describing each line. In this case, the variables and methods are self-describable. It's better to comment what and why solves this logic and not how.
| pass | ||
|
|
||
| if was_mentioned or is_reply_to_bot: | ||
| await message.reply("beep boop this is my impression of a non-commital robot") # Reply to the message with a funny comment ig |
There was a problem hiding this comment.
Unnecessary comment. Also, as I suggested in #14, we can create a hash table with the answers and pick a random one.
4c3b114 to
d5a6227
Compare
Used the
bot.eventdecorator to allow bot to respond to replies and mentions, only when it isn't the bot itself. Also removed unneeded functionget_or_create...because the game I made to test isn't implemented anymore.Closes: #14