質問編集履歴
1
変更点 UIの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -133,139 +133,3 @@
|
|
133
133
|
# Botの起動とDiscordサーバーへの接続
|
134
134
|
client.run(data)
|
135
135
|
```
|
136
|
-
|
137
|
-
main.py
|
138
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------
|
139
|
-
import discord
|
140
|
-
import os
|
141
|
-
import os;
|
142
|
-
|
143
|
-
import ma as ma
|
144
|
-
|
145
|
-
print(os.getcwd())
|
146
|
-
import subprocess
|
147
|
-
import sys
|
148
|
-
import random
|
149
|
-
import asyncio
|
150
|
-
import string
|
151
|
-
import secrets
|
152
|
-
import discord
|
153
|
-
import os
|
154
|
-
from discord.ext import commands
|
155
|
-
import random
|
156
|
-
from discord import Permissions
|
157
|
-
import asyncio
|
158
|
-
import shutil
|
159
|
-
|
160
|
-
|
161
|
-
# 読込むファイルのパスを宣言する
|
162
|
-
file_name = "./token.txt"
|
163
|
-
|
164
|
-
try:
|
165
|
-
file = open(file_name)
|
166
|
-
data = file.read()
|
167
|
-
print(data)
|
168
|
-
except Exception as e:
|
169
|
-
print(e)
|
170
|
-
finally:
|
171
|
-
file.close()
|
172
|
-
|
173
|
-
|
174
|
-
# 接続に必要なオブジェクトを生成
|
175
|
-
client = discord.Client()
|
176
|
-
|
177
|
-
# 起動時に動作する処理
|
178
|
-
@client.event
|
179
|
-
async def on_ready():
|
180
|
-
# 起動したらターミナルにログイン通知が表示される
|
181
|
-
print('----------------')
|
182
|
-
print('ログインしました')
|
183
|
-
print('----------------')
|
184
|
-
print('')
|
185
|
-
print('BOT表示名:', client.user.name) # Botの名前
|
186
|
-
print('BOTのID:', client.user.id) # ID
|
187
|
-
print('Dicord.pyのバージョン:', discord.__version__)
|
188
|
-
ch = client.get_channel(947469205538762812)
|
189
|
-
print('')
|
190
|
-
guild_count = len(client.guilds)
|
191
|
-
game = discord.Game(f'{guild_count} サーバーに導入されています')
|
192
|
-
await client.change_presence(activity=discord.Game(name=game))
|
193
|
-
print('ログインしました {0.user}'.format(client))
|
194
|
-
await ch.send("BOTが起動しました!")
|
195
|
-
|
196
|
-
|
197
|
-
# メッセージ受信時に動作する処理
|
198
|
-
@client.event
|
199
|
-
async def on_message(message):
|
200
|
-
guild_count = len(client.guilds)
|
201
|
-
game = discord.Game(f'{guild_count} サーバーに導入されています')
|
202
|
-
await client.change_presence(activity=discord.Game(name=game))
|
203
|
-
# メッセージ送信者がBotだった場合は無視する
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
if message.author.bot:
|
208
|
-
return
|
209
|
-
# 「/neko」と発言したら「にゃーん」が返る処理
|
210
|
-
if message.content == 'spb!認証':
|
211
|
-
|
212
|
-
passseta = random.randint(11111111, 9999999999)
|
213
|
-
passsetb = random.randint(11111111, 9999999999)
|
214
|
-
passsetc = random.randint(11111111, 9999999999)
|
215
|
-
print(passseta)
|
216
|
-
print(passsetb)
|
217
|
-
print(passsetc)
|
218
|
-
passlock = passseta+passsetb+passsetc
|
219
|
-
channel = message.channel
|
220
|
-
await channel.send("認証コードを30秒以内に送ってください")
|
221
|
-
await channel.send(str('`認証コード : `')+str(passlock))
|
222
|
-
path = str('./')+str(message.guild.id)+str(message.channel.id)
|
223
|
-
file_name = str('./')+str(message.guild.id)+str(message.channel.id)
|
224
|
-
file = open(file_name, 'w')
|
225
|
-
file.write(str(passlock))
|
226
|
-
file.close()
|
227
|
-
file = open(file_name)
|
228
|
-
file.close()
|
229
|
-
|
230
|
-
# 待っているものに該当するかを確認する関数
|
231
|
-
def check(m):
|
232
|
-
# メッセージが `おはよう` かつ メッセージを送信したチャンネルが
|
233
|
-
# コマンドを打ったチャンネルという条件
|
234
|
-
path = str('./')+str(message.guild.id)+str(message.channel.id)
|
235
|
-
file_name = str('./')+str(message.guild.id)+str(message.channel.id)
|
236
|
-
f = open(path)
|
237
|
-
file = open(file_name)
|
238
|
-
data = file.read()
|
239
|
-
print(data)
|
240
|
-
file.close()
|
241
|
-
file = open(file_name)
|
242
|
-
file.close()
|
243
|
-
return m.content == data and m.channel == channel
|
244
|
-
|
245
|
-
try:
|
246
|
-
# wait_forを用いて、イベントが発火し指定した条件を満たすまで待機する
|
247
|
-
msg = await client.wait_for('message', check=check, timeout=30)
|
248
|
-
# wait_forの1つ目のパラメータは、イベント名の on_がないもの
|
249
|
-
# 2つ目は、待っているものに該当するかを確認する関数 (任意)
|
250
|
-
# 3つ目は、タイムアウトして asyncio.TimeoutError が発生するまでの秒数
|
251
|
-
|
252
|
-
# asyncio.TimeoutError が発生したらここに飛ぶ
|
253
|
-
except asyncio.TimeoutError:
|
254
|
-
await channel.send(f'{message.author.mention}さん、認証時間切れです')
|
255
|
-
else:
|
256
|
-
# メンション付きでメッセージを送信する。
|
257
|
-
await channel.send(f'{msg.author.mention}さん、認証は成功しました')
|
258
|
-
ROLE_ID = 975753269420884048
|
259
|
-
ID_ROLE_WELCOME = 975753269420884048 # 付けたい役職のID
|
260
|
-
# channel_id から Channel オブジェクトを取得
|
261
|
-
role = guild.get_role(ID_ROLE_WELCOME)
|
262
|
-
# リアクションを付けたメンバーに役職を付与
|
263
|
-
await member.add_roles(role)
|
264
|
-
# 分かりやすいように歓迎のメッセージを送る
|
265
|
-
await channel.send('いらっしゃいませ!')
|
266
|
-
|
267
|
-
|
268
|
-
# Botの起動とDiscordサーバーへの接続
|
269
|
-
client.run(data)
|
270
|
-
|
271
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------
|