-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
conversion command #77
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from discord.ext import commands | ||
from unit_converter.converter import convert, converts | ||
|
||
|
||
class ConversionCog(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot # This line in the constructor is required | ||
|
||
@commands.command() | ||
async def convert( | ||
self, ctx, inputunit, outputunit | ||
): # the ctx parameter is short for 'context' | ||
"""type your input and output units""" | ||
save = convert(inputunit, outputunit) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please try and use variable names that accurately describe the data to which they refer. This benefits you and others who might try and read, edit, and/or improve your code in the future 🙂 |
||
|
||
await ctx.send( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be nice as an embed. Try the following after adding embed = discord.Embed(title="Unit Conversion")
embed.add_field(name="Input Quantity", value=inputunit)
embed.add_field(name="Output Unit", value=outputunit)
embed.add_field(name="Result", value=save)
await ctx.send(embed=embed) Feel free to give it some colour if you'd like 🙂 it is up to you. |
||
"You are converting from " | ||
+ inputunit | ||
+ " to " | ||
+ str(save) | ||
+ " " | ||
+ outputunit | ||
) | ||
|
||
|
||
def setup(bot): | ||
bot.add_cog(ConversionCog(bot)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ polling | |
pillow | ||
pyquery | ||
unit-converter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an accurate description of how the command works? It seems as though the input isn't just a unit, but is actually a quantity with a unit. Remember that although you have read the documentation or examples for the
convert
function you imported fromunit-converter
, your users have not, and neither have other programmers who may be viewing and working with your code. Make sure you use variable names and include documentation that is accurate to the way your code works! 😄