Skip to content

Commit 6f642c4

Browse files
authored
Merge pull request #613 from Dorukyum/timeout-example
Add timeout example
2 parents 6927707 + f215f71 commit 6f642c4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/timeout.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import datetime
2+
3+
import discord
4+
5+
bot = discord.Bot()
6+
7+
8+
@bot.command()
9+
async def timeout(ctx, member: discord.Member, minutes: int):
10+
"""Apply a timeout to a member"""
11+
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+
"""
22+
23+
24+
bot.run("TOKEN")

0 commit comments

Comments
 (0)