Reputation: 21
so I type taxcalc (amount) but it wont work. I don't understand what I am doing wrong. The command is supposed to show the tax calculation by 8 percent of the given amount, but the bot just will not respond to the command. I am wondering if I am configuring the bot wrong but it could also be the code that is wrong.
# bot.py
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user.name} has connected to Discord!')
@client.event
async def taxcalc(ctx, x: str):
x = CHECK_M_K(str(x))
lost = x*0.08
lost2 = x*0.033045
plus = round(x + x*0.12)
plost = int(plus-lost2)
print("plus: "+str(plus))
print("plus lost: " + str(plost))
for i in range(int(plus-lost2), plus):
if x > int(1e12):
await ctx.channel.send("***IMPOSSIBLE! You definitely DO NOT have more than 1 trillion!!***")
break
temp = i
lost = i-x
lost = "{:,}".format(lost)
i -= round(i*0.08)
if (i == x):
x = temp
x = "{:,}".format(x)
embed = discord.Embed(title="Tax Calculator", description="Amount expected to pay: `⏣ "+ x + "`\n" + "Amount lost by tax: `⏣ "+lost+"`\n" + "Tax rate: 8%", color=0xace1af)
await ctx.channel.send(embed=embed)
print(x)
break
elif x == 20:
embed = discord.Embed(title="Tax Calculator", description="Amount expected to pay: `⏣ "+ str(x+2) + "`\n" + "Amount lost by tax: `⏣ 2`\n" + "Tax rate: 8%", color=0xace1af)
await ctx.channel.send(embed=embed)
print(x)
break
elif x > 6 and x < 19:
embed = discord.Embed(title="Tax Calculator", description="Amount expected to pay: `⏣ "+ str(x+1) + "`\n" + "Amount lost by tax: `⏣ 1`\n" + "Tax rate: `8%`", color=0xace1af)
await ctx.channel.send(embed=embed)
print(x)
break
elif x <= 6:
embed = discord.Embed(title="Tax Calculator", description="Amount expected to pay: `⏣ "+ str(x) + "`\n" + "Amount lost by tax: `⏣ 0`\n" + "Tax rate: `8%`", color=0xace1af)
await ctx.channel.send(embed=embed)
print(x)
break
else:
i = 0
client.run(token removed lul)```
Upvotes: 0
Views: 55
Reputation: 831
The error is in the data type specification.
You are using Commands API
and thus you can't use Client
Object as it not made for this. When you try to make commands then you need to use Bot
objects of the Commands API
. Otherwise the bot will not work but just go online.
You are making a command
, and then making it an event
. You have made a command which can be used by the user, so is not an event
but it is an command()
. So you are basically using Commands API
of the library.
You are first saying that the x
in the function is a string and then multiplying it with a number. You can not multiply a string with int. Due to the library discord.py the error will not be visible except the library errors. So you can't see the basic errors. You need to pay attention to what you do in the script.
discord.Client
REMOVE THIS LINE
This is not made for the Commands API
whereas it is made for event
s. You need to use the commands declaration for that.
(i) Import the library like this:
import discord
from discord.ext import commands
(ii) Declare the bot like:
client = commands.Bot(command_prefix="!")
Now you will be able to use your commands like: !taxcalc <value>
. This will specifically let you use the commands.
event
discriminator. It is a command()
so you need to change it.You need to change the code from:
@client.event
to:
@client.command()
To fix it, you need to change two lines.
(i) The first line:
async def taxcalc(ctx, x: str):
Change it to:
async def taxcalc(ctx, x: int):
(ii) The second line:
x = CHECK_M_K(str(x))
Change it to:
x = CHECK_M_K(x)
If you do all of the changes as mentioned above, then your code would be fixed and your bot will run correctly. If you get any issues, please do ask them in the comments. :)
Thank You! :D
Upvotes: 1