2

I am creating a command to calculate time needed to get "Familiars" in a particular server, but I am having troubles actually making the command itself. This is what I have done so far to get my grounds on making a command yet when I run test, nothing happens. Can anyone help?

import discord
from discord.ext import commands

client = discord.Client()

bot = commands.Bot(command_prefix='//')


@bot.command()
async def test(ctx):
    await ctx.send('test')
#edited in 'await' above ^
#Familiars Calculator Portion:
import discord
from discord.ext import commands

from Commands import bot


@bot.command
async def calculator():
class calculate:
    def values(self):
        fam = 35353
        xp: int = int(input("Enter your current xp: "))
        msg = 1
        while xp < fam:
            xp += 15
            msg += 1
            days_to_fam: int = round(msg * 2 / (60 * 24))
            hours_to_fam: int = round(msg * 2 / 60)
            hours_to_fam %= 24
            minutes_to_fam: int = round(msg * 2)
            minutes_to_fam %= 60

            embed = discord.Embed(title="Statistics needed to reach fam:",color=0xffffff))
            embed = discord.Embed(description="Messages: ", int(msg), " (roughly).", "\nDays: ", days_to_fam, "\nHours: ", hours_to_fam, "\nMinutes:", minutes_to_fam)

        print('\nStatistics needed to reach fam: ', "\nMessages:", int(msg), "(roughly)", "\nDays:", days_to_fam,
          "\nHours:", hours_to_fam, "\nMinutes:", minutes_to_fam)
2
  • You need to use await, await ctx.send('test'). Commented Jul 16, 2020 at 5:46
  • I have done that and it doesn't work @InsertCheesyLine. Nothing happens. No response whatsoever. It isn't a discord permission error either. Commented Jul 16, 2020 at 6:14

2 Answers 2

1

There are some errors in your code:

  • client = discord.Client(), you don't need it so you can delete it.
  • @bot.command() #You forgot to put parentheses
    async def calculator(ctx): #ctx MUST be the fist argument
    
  • Your embed definition is wrong, as in your code, it will just be a default embed with a custom description field.
    #Change
    embed = discord.Embed(title="Statistics needed to reach fam:",color=0xffffff))
    embed = discord.Embed(description="Messages: ", int(msg), " (roughly).", "\nDays: ", days_to_fam, "\nHours: ", hours_to_fam, "\nMinutes:", minutes_to_fam)
    #to
    embed = discord.Embed(title="Statistics needed to reach fam:",
                          description=f"Messages: {int(msg)} (roughly).\nDays: {days_to_fam}\nHours: {hours_to_fam}\nMinutes: {minutes_to_fam}"
                          color=0xffffff,
    )
    
  • You don't need to import Bot (from Commands import Bot). Also, you don't need to import the same things twice, import what you need at the beginning of your code.
  • To send a message, use ctx.send(). How to use it: await ctx.send("Your message") or await ctx.send(embed=embed)

PS: Why would you create a class in your command, why do you need it?

Sign up to request clarification or add additional context in comments.

Comments

0

just do that it is very simple and easy


@bot.command(pass_context=True)
async def add(ctx, a:int, b:int):
    await ctx.send(f"The calculation result is:\n***{a+b}***")
    
@bot.command(pass_context=True)
async def subtract(ctx, a:int, b:int):
    await ctx.send(f"The calculation result is:\n***{a-b}***")
    
@bot.command(aliases=["calmultiply"])
async def multiply(ctx, a:int, b:int):
    await ctx.send(f"The calculation result is:\n***{a*b}***")
    
@bot.command(pass_context=True)
async def devide(ctx, a:int, b:int):
    await ctx.send(f"The calculation result is:\n***{a/b}***")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.