Answer the question
In order to leave comments, you need to log in
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:
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question