1
1
1AAAhelpmeAAA12022-03-10 13:59:17
Python
1AAAhelpmeAAA1, 2022-03-10 13:59:17

Need help using datetime in a discord bot based on discord.py.?

recently I decided to make a bot in the discord, add a simple calculator to it, as well as a function to display the date (so far only the current number)
I turned on the bot, after which I decided to check its functions on my server, the calculator worked fine, but when I wanted to display the date (current number) I got the following in the console:

spoiler
C:\Users\User\Desktop\для проекта\main.py:10: RuntimeWarning: coroutine 'Command
.__call__' was never awaited
print('We have logged in as {0.user}'.format(client))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Ignoring exception in command print:
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\core.py", line 855, in invoke
await self.prepare(ctx)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\core.py", line 789, in prepare
await self._parse_arguments(ctx)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\core.py", line 706, in _parse_arguments
kwargs[name] = await self.transform(ctx, param)
File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\discord\ext
\commands\core.py", line 542, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: text is a required argument
that is missing.

I can't figure out what I did wrong
here is my code:
import discord
from discord.ext import commands
from datetime import datetime

client = discord.ext.commands.Bot(command_prefix = "D.")

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.command()
async def print(ctx, *, text):
    now = datetime.now()
    dt_string = now.strftime("%d")
    await ctx.send(f'{dt_string}')

@client.command()
async def prindt(ctx,arg1,arg2,arg3):
    a = arg1
    b = arg2
    c = arg3
    if (b) == "*" :
        a = int(a) * int(c)
    else:
        if (b) == "+":
            a = int(a) + int(c)
        else:
            if (b) == "-":
                a = int(a) + int(c)
            else:
                if (b) == "/":
                    a = int(a) / int(c)    
    await ctx.send(f'{int(a)}')

client.run('my_token')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
# ., 2022-03-10
@1AAAhelpmeAAA1

Your bot expects text, you yourself added it to the argument Why the hell in the text function, I don’t know. So everything is ok:
async def print(ctx, *, text):
async def print(ctx):

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question