-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (63 loc) · 2.33 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import discord
from discord.ext.commands import Bot
import os
intents = discord.Intents.default()
bot = Bot(command_prefix='!kebi ', intents=intents)
bot.remove_command("help")
if __name__ == '__main__':
@bot.event
async def on_ready():
print("Hi, logged in as " + bot.user.name, end='\n')
@bot.command()
async def hello(ctx):
await ctx.reply('안녕하세요, 공부하는 케비에요.')
@bot.command()
async def help(ctx):
cmds = ""
cmds += ("channels : 채널 별 아이디 확인" + '\n')
cmds += ("check {채널아이디} : 해당 채널에 접속한 멤버 리스트 확인" + '\n')
await ctx.reply(cmds)
@bot.command()
async def channels(ctx):
channels = bot.get_all_channels()
msg = ""
for ch in channels :
if ch.guild is not ctx.channel.guild :
continue
if isinstance(ch, discord.TextChannel):
msg += ("[채팅채널]" + '\t' + str(ch.name) + "\t" + str(ch.id) + '\n')
elif isinstance(ch, discord.VoiceChannel):
msg += ("[음성채널]" + '\t' + str(ch.name) + "\t" + str(ch.id) + '\n')
await ctx.reply(msg)
def isValidArgs(argNum, *args) :
if args is None or args is [] :
return False
if len(args) is 0 :
if argNum is 0 :
return True
else :
return False
if argNum != len(args) :
return False
return True
@bot.command()
async def check(ctx, *args):
if not isValidArgs(1, *args) :
msg = "명령어를 잘못 입력하셨네요." + '\n'
msg += "check {채널아이디} : 해당 채널에 접속한 멤버 리스트 확인"
await ctx.reply(msg)
return
channelId = int(args[0])
channel = bot.get_channel(channelId)
mems = channel.members
if len(mems) is 0 :
await ctx.reply("아무도 없습니다!")
return
msg = "== 현재 " + str(channel.name) + "채널 접속 멤버 ==" + '\n'
msg += ("☑️ " + str(len(mems)) + "명 접속중" + '\n')
msg += '\n'
for mem in mems :
msg += (str(mem.display_name) + '\n')
else :
await ctx.reply(msg)
bot.run(os.environ['TOKEN'])