Skip to content

Commit f215f71

Browse files
authored
Use Member.timeout_for
1 parent 9e646c6 commit f215f71

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

examples/timeout.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77

88
@bot.command()
99
async def timeout(ctx, member: discord.Member, minutes: int):
10-
"""Set timeout on a member"""
10+
"""Apply a timeout to a member"""
1111

12-
now = discord.utils.utcnow() # get current time
13-
until = now + datetime.timedelta(minutes=minutes) # add the duration
14-
await member.timeout(until=until)
15-
await ctx.respond(f"Member timed out for {minutes} minutes.")
12+
duration = datetime.timedelta(minutes=minutes)
13+
await member.timeout_for(duration)
14+
await ctx.reply(f"Member timed out for {minutes} minutes.")
15+
16+
"""
17+
The method used above is a shortcut for
18+
19+
until = discord.utils.utcnow() + datetime.timedelta(minutes=minutes)
20+
await member.timeout(until)
21+
"""
1622

1723

1824
bot.run("TOKEN")

0 commit comments

Comments
 (0)