I am trying to make a python time dif code in discord. Old versions of this code on the Internet are not working. I don’t know what to do.
I tried this but still there are a lot of mistakes. Old posts also didn’t help me. Who can give me the right code?
import discord
import credits
import random
def snowflake_time(id):
return datetime.datetime.utcfromtimestamp(((id >> 22) + 1420070400000) / 1000)
@bot.command(name='timedif')
async def timedif(ctx, id1, id2):
try:
id_1 = int(id_1)
id_2 = int(id_2)
except:
await ctx.reply("Incorrect ID")
msg1 = await ctx.fetch_message(id_1)
msg2 = await ctx.fetch_message(id_2)
time1 = discord.utils.snowflake_time(int(id1))
time2 = discord.utils.snowflake_time(int(id2))
ts_diff = time2 - time1
secs = abs(ts_diff.total_seconds())
embed = discord.Embed(title="**Time Difference**", description=f"""IDs: {id_1}, {id_2}
Time difference between the 2 IDs: {answer}""")
await ctx.reply(embed=embed)
bot.run(token)```