-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
46 lines (32 loc) · 1.09 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import asyncio
import os
import random
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv("TOKEN")
GUILD_ID = int(os.getenv("GUILD_ID")) # type: ignore
bot = discord.Bot(debug_guilds=[GUILD_ID])
@bot.slash_command(
name="muterng",
description="Mutes a random person for an amount of time (in seconds)",
)
@discord.default_permissions(mute_members=True)
async def hello(ctx: discord.ApplicationContext, time: int = 20) -> None:
voice = ctx.author.voice # type: ignore
if not voice:
await ctx.respond("You are not in a voice channel")
return
users = list(voice.channel.voice_states.keys()) # type: ignore
user = await ctx.guild.fetch_member(random.choice(users)) # type: ignore
if not user:
await ctx.respond("Command Failed!")
return
await user.edit(mute=True)
await ctx.respond(f"{user.display_name} has been muted for {time} seconds")
await asyncio.sleep(time)
await user.edit(mute=False)
@bot.event
async def on_ready() -> None:
print(f"{bot.user} is Online!")
bot.run(TOKEN) # type: ignore