-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
34 lines (27 loc) · 999 Bytes
/
main.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
import os
import random
import discord
from discord.ext import commands
from typing import Optional
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=".", intents=intents)
@bot.command()
async def darts(ctx: commands.Context, channel_name: str, name: Optional[str] = None):
if ctx.author.bot:
return
await ctx.message.delete()
channel_name = channel_name.lstrip("#")
channels = ctx.guild.voice_channels
for ch in channels:
if ch.name == channel_name:
if not ch.members:
await ctx.send(f"#{channel_name}には誰もいません")
return
member = random.choice(ch.members)
msg = f"{name}に選ばれました!" if name is not None else "あなたが選ばれました!"
await member.send(msg)
return
await ctx.send(f"#{channel_name}が存在しません")
TOKEN = os.environ.get("DISCORD_BOT_TOKEN")
bot.run(TOKEN)