-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisbot.py
More file actions
60 lines (46 loc) · 2.06 KB
/
Copy pathdisbot.py
File metadata and controls
60 lines (46 loc) · 2.06 KB
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
import discord
import getsongs
import gosh
# 接続に使うオブジェクト / starting
client = discord.Client()
# 起動した確認 / confirm starting
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
# こっから処理 / processing
@client.event
async def on_message(message):
# 課題曲 曲数 難易度範囲 / ex. 課題曲 3 17-19)
if message.content.startswith("課題"):
if client.user != message.author.name:
# メッセージの内容を取得
currentMessage = message.content
# 曲数とか難易度の範囲とかをsplitして変数に格納
sentMessage = currentMessage.split()
numOfSongs = int(sentMessage[1])
rangeOfDifficulty = sentMessage[2].split("-")
# 難易度の範囲を数字に直す
difficulty = []
for i in range(int(rangeOfDifficulty[0]), int(rangeOfDifficulty[1])+1 ):
difficulty.append(i)
# 曲と難易度をgetSongs関数で取得
songs, difficultyOfSongs = getsongs.getSongs(numOfSongs, difficulty)
# 帰ってきたメッセージを合体して送信
sendMessage = ""
for i in range(len(songs)):
sendMessage = sendMessage + f'{songs[i]} 足{difficultyOfSongs[i]}\n'
channel = message.channel
await channel.send(sendMessage)
if message.content.startswith("消去"):
if client.user != message.author.name:
await message.channel.purge()
if message.content.startswith("help"):
if client.user != message.author.name:
channel = message.channel
await channel.send("課題 {曲数} {難易度の範囲} と送信してください。\n1つの難易度の場合は15-15のように入力してください。\nex.\) 課題 3 15-18\n")
# ここにはdiscordのbotのトークンを入れる / fill in "token"
TOKEN = gosh.requestsToken()
client.run(TOKEN)