So, i want to do an Timestamp to my Giveaway Command for when the Giveaway Ends. Now the Timestamp is 01.01.1970, i imported datetime and did an convert system. There isnt any Error, so it must been my Code. Any ideas how i can do that? I have no clue how i can change that
JavaScript
x
16
16
1
def convert(time):
2
pos = ["s", "m", "h", "d"]
3
4
time_dict = {"s": 1, "m": 60, "h": 3600, "d": 3600 * 24}
5
6
unit = time[-1]
7
8
if unit not in pos:
9
return -1
10
try:
11
val = int(time[:-1])
12
except:
13
return -2
14
15
return val * time_dict[unit]
16
My Convert System
JavaScript
1
81
81
1
@client.command()
2
@commands.has_permissions(administrator=True)
3
async def gewinnspiel(ctx):
4
await ctx.send(
5
"**Beginnen wir mit diesem Gewinnspiel! Beantworten diese Fragen innerhalb von 15 Sekunden!**"
6
)
7
8
questions = [
9
"In welchem ••Kanal soll es gehostet werden?",
10
"Wie lange soll das Giveaway dauern? (s|m|h|d)",
11
"Was ist der Preis des Giveaways?"
12
]
13
14
answers = []
15
16
def check(m):
17
return m.author == ctx.author and m.channel == ctx.channel
18
19
for i in questions:
20
await ctx.send(i)
21
22
try:
23
msg = await client.wait_for('message', timeout=15.0, check=check)
24
except asyncio.TimeoutError:
25
await ctx.send(
26
'**Du hast nicht in zeit geantwortet! Bitte sei schneller.**')
27
return
28
else:
29
answers.append(msg.content)
30
try:
31
c_id = int(answers[0][2:-1])
32
except:
33
await ctx.send(
34
f"**Du hast den Kanal nicht richtig Makiert. Versuche es so: {ctx.channel.mention} nächstes mal.**"
35
)
36
return
37
38
channel = client.get_channel(c_id)
39
40
time = convert(answers[1])
41
if time == -1:
42
await ctx.send(
43
f"**Du hast die Zeit nicht mit einer richtigen Einheit beantwortet. Benutze beim nächsten Mal (s|m|h|d)!**"
44
)
45
return
46
elif time == -2:
47
await ctx.send(
48
f"**Die Zeit muss eine ganze Zahl sein. Bitte geb beim nächsten Mal eine ganze Zahl ein.**"
49
)
50
return
51
52
prize = answers[2]
53
54
await ctx.send(
55
f"Das Gewinnspiel wird in {channel.mention} sein und dauert {answers[1]}!"
56
)
57
58
timestamp = time
59
embed = nextcord.Embed(
60
title="Gewinnspiel!",
61
description=
62
f"Reagiere mit :tada: um teilzunehmen!nPreis: {prize}n Dauer: {answers[1]}nHosted von: {ctx.author.mention}",timestamp=(datetime.datetime.utcfromtimestamp(timestamp)),
63
color=ctx.author.color)
64
65
my_msg = await channel.send(embed=embed)
66
67
await my_msg.add_reaction('🎉')
68
69
await asyncio.sleep(time)
70
71
new_msg = await channel.fetch_message(my_msg.id)
72
73
users = await new_msg.reactions[0].users().flatten()
74
users.pop(users.index(client.user))
75
76
winner = random.choice(users)
77
78
await channel.send(
79
f"**Herzlichen Glückwunsch!**n {winner.mention} hat {prize} Gewonnen!"
80
)
81
And this is my Code for the Giveaway
Advertisement
Answer
I fixed it thank to @Tim Roberts Comment, First i imported time then i renamed my Time Variable to Timer and changed the Timestamp = Value
JavaScript
1
4
1
import Time
2
3
timestamp = time.time() + Timer
4