質問編集履歴
2
書式を修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,6 +32,10 @@
|
|
32
32
|
|
33
33
|
```
|
34
34
|
|
35
|
+
|
36
|
+
|
37
|
+
```
|
38
|
+
|
35
39
|
#coding: utf-8
|
36
40
|
|
37
41
|
|
@@ -192,7 +196,7 @@
|
|
192
196
|
|
193
197
|
|
194
198
|
|
195
|
-
|
199
|
+
```
|
196
200
|
|
197
201
|
### 試したこと
|
198
202
|
|
1
ソースコードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,10 +28,170 @@
|
|
28
28
|
|
29
29
|
```ここに言語名を入力
|
30
30
|
|
31
|
-
|
31
|
+
python
|
32
32
|
|
33
33
|
```
|
34
34
|
|
35
|
+
#coding: utf-8
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
# Discordアプリのトークンを入力
|
40
|
+
|
41
|
+
BOT_TOKEN = "ここにトークンを入れます"
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
# パッケージのインポートとインスタンス作成
|
46
|
+
|
47
|
+
import discord
|
48
|
+
|
49
|
+
import random
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
p_list = []
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
client = discord.Client()
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
# ログイン&準備が完了したら一度だけ実行される
|
62
|
+
|
63
|
+
@client.event
|
64
|
+
|
65
|
+
async def on_ready():
|
66
|
+
|
67
|
+
# コンソールにBOTとしてログインした名前とUSER-IDを出力
|
68
|
+
|
69
|
+
print('Logged in as')
|
70
|
+
|
71
|
+
print('BOT-NAME :', client.user.name)
|
72
|
+
|
73
|
+
print('BOT-ID :', client.user.id)
|
74
|
+
|
75
|
+
print('------')
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
# メッセージを受信するごとに実行される
|
80
|
+
|
81
|
+
@client.event
|
82
|
+
|
83
|
+
async def on_message(message):
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
# BOTとメッセージの送り主が同じ人なら処理しない
|
88
|
+
|
89
|
+
if client.user == message.author:
|
90
|
+
|
91
|
+
return
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
#チャンネルメンバー取得
|
96
|
+
|
97
|
+
global p_list
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
# メッセージの頭が "!hello" なら実行する
|
102
|
+
|
103
|
+
if message.content.startswith('!hello'):
|
104
|
+
|
105
|
+
# メッセージが送られてきたチャンネルに "Hello World..." を返す
|
106
|
+
|
107
|
+
await client.send_message(message.channel, 'グループ分け開発中だよ!')
|
108
|
+
|
109
|
+
await client.send_message(message.channel, message.author.name + "さんの要求を受け付けました")
|
110
|
+
|
111
|
+
vcmembers(message,355973155283533828)
|
112
|
+
|
113
|
+
#voice_channel = discord.utils.get(message.server.channels, id = 355973155283533828, type=discord.ChannelType.voice)
|
114
|
+
|
115
|
+
#voice_channel = discord.utils.get(message.server.channels, id = 355973155283533828)
|
116
|
+
|
117
|
+
#print(voice_channel)
|
118
|
+
|
119
|
+
#await client.send_message(message.channel,sendlist(p_list))
|
120
|
+
|
121
|
+
await client.send_message(message.channel,'リストに代入しました')
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
#ボイスチャンネルのユーザ名取得
|
126
|
+
|
127
|
+
def vcmembers(ctx, voice_channel_id):
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
voice_channel = discord.utils.get(ctx.server.channels, id = voice_channel_id)
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
if voice_channel is None:
|
138
|
+
|
139
|
+
return client.say("ボイスチャンネルではありません")
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
members = voice_channel.voice_members
|
144
|
+
|
145
|
+
member_names = '\n'.join([x.name for x in members])
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
embed = discord.Embed(title = "{} member(s) in {}".format(len(members), voice_channel.name),
|
150
|
+
|
151
|
+
description = member_names,
|
152
|
+
|
153
|
+
color=discord.Color.blue())
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
return client.say(embed = embed)
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
#リストを表示
|
162
|
+
|
163
|
+
async def sendlist(list):
|
164
|
+
|
165
|
+
global p_list
|
166
|
+
|
167
|
+
bunsyou =''
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
# if bunsyou is None
|
172
|
+
|
173
|
+
# return bunsyou
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
for p in p_list:
|
178
|
+
|
179
|
+
if len(p) >=1:
|
180
|
+
|
181
|
+
bunsyou += p +'\n'
|
182
|
+
|
183
|
+
bunsyou +='\n\n'
|
184
|
+
|
185
|
+
return bunsyou
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
# APP(BOT)を実行
|
190
|
+
|
191
|
+
client.run(BOT_TOKEN)
|
192
|
+
|
193
|
+
|
194
|
+
|
35
195
|
|
36
196
|
|
37
197
|
### 試したこと
|