回答編集履歴
4
修正
test
CHANGED
@@ -178,10 +178,6 @@
|
|
178
178
|
|
179
179
|
async def move_to_none():
|
180
180
|
|
181
|
-
# 接続に利用するオブジェクト
|
182
|
-
|
183
|
-
client = discord.Client()
|
184
|
-
|
185
181
|
# 該当サーバーの特定のチャンネルIDを入れてください。
|
186
182
|
|
187
183
|
talk_channel_id =878830663808213026
|
3
文法修正
test
CHANGED
@@ -386,85 +386,85 @@
|
|
386
386
|
|
387
387
|
|
388
388
|
|
389
|
-
if message.content.startswith('/ver'): # startswithにすることにより、/ver, /ver abc, /versionなどに反応します。
|
390
|
-
|
391
|
-
send_message = '> ver1.0'
|
392
|
-
|
393
|
-
await message.channel.send(send_message)
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
# イベント入るたびに初期化はまずいのでグローバル変数で
|
398
|
-
|
399
|
-
global ModeFlag
|
400
|
-
|
401
|
-
# 一応終了するコマンドも用意しておく
|
402
|
-
|
403
|
-
if message.content == '!exit':
|
404
|
-
|
405
|
-
await message.channel.send('ノシ')
|
406
|
-
|
407
|
-
sys.exit()
|
408
|
-
|
409
|
-
# google検索モード(次に何か入力されるとそれを検索)
|
410
|
-
|
411
|
-
if ModeFlag == 1:
|
412
|
-
|
413
|
-
kensaku = message.content
|
414
|
-
|
415
|
-
ModeFlag = 0
|
416
|
-
|
417
|
-
count = 0
|
418
|
-
|
419
|
-
# 日本語で検索した上位5件を順番に表示
|
420
|
-
|
421
|
-
for url in search(kensaku, lang="jp",num = 5):
|
422
|
-
|
423
|
-
await message.channel.send(url)
|
424
|
-
|
425
|
-
count += 1
|
426
|
-
|
427
|
-
if(count == 5):
|
428
|
-
|
429
|
-
break
|
430
|
-
|
431
|
-
# google検索モードへの切り替え
|
432
|
-
|
433
|
-
if message.content == '/google':
|
434
|
-
|
435
|
-
ModeFlag = 1
|
436
|
-
|
437
|
-
await message.channel.send('検索するワードをチャットで発言してね')
|
438
|
-
|
439
|
-
# 単純な応答
|
440
|
-
|
441
|
-
if message.content == 'bot君いる?':
|
442
|
-
|
443
|
-
await message.channel.send('私bot君。あなたの後ろにいるよ。')
|
444
|
-
|
445
|
-
# 特定の文字から始まる文章が発言されたとき
|
446
|
-
|
447
|
-
if message.content.startswith('負け'):
|
448
|
-
|
449
|
-
lose = message.author.name + "の負け!w"
|
450
|
-
|
451
|
-
await message.channel.send(lose)
|
452
|
-
|
453
|
-
#リプライを受け取った時
|
454
|
-
|
455
|
-
if client.user in message.mentions:
|
456
|
-
|
457
|
-
reply = f'{message.author.mention} うるさいよ。'
|
458
|
-
|
459
|
-
await message.channel.send(reply)
|
460
|
-
|
461
|
-
# これについては触れないよ。
|
462
|
-
|
463
|
-
if message.content.startswith("なんだかんだ"):
|
464
|
-
|
465
|
-
kanda = "かんだ・・・神田ァ!?\n" + "https://www.youtube.com/watch?v=KUwpssJX37M"
|
466
|
-
|
467
|
-
await message.channel.send(kanda)
|
389
|
+
if message.content.startswith('/ver'): # startswithにすることにより、/ver, /ver abc, /versionなどに反応します。
|
390
|
+
|
391
|
+
send_message = '> ver1.0'
|
392
|
+
|
393
|
+
await message.channel.send(send_message)
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
# イベント入るたびに初期化はまずいのでグローバル変数で
|
398
|
+
|
399
|
+
global ModeFlag
|
400
|
+
|
401
|
+
# 一応終了するコマンドも用意しておく
|
402
|
+
|
403
|
+
if message.content == '!exit':
|
404
|
+
|
405
|
+
await message.channel.send('ノシ')
|
406
|
+
|
407
|
+
sys.exit()
|
408
|
+
|
409
|
+
# google検索モード(次に何か入力されるとそれを検索)
|
410
|
+
|
411
|
+
if ModeFlag == 1:
|
412
|
+
|
413
|
+
kensaku = message.content
|
414
|
+
|
415
|
+
ModeFlag = 0
|
416
|
+
|
417
|
+
count = 0
|
418
|
+
|
419
|
+
# 日本語で検索した上位5件を順番に表示
|
420
|
+
|
421
|
+
for url in search(kensaku, lang="jp",num = 5):
|
422
|
+
|
423
|
+
await message.channel.send(url)
|
424
|
+
|
425
|
+
count += 1
|
426
|
+
|
427
|
+
if(count == 5):
|
428
|
+
|
429
|
+
break
|
430
|
+
|
431
|
+
# google検索モードへの切り替え
|
432
|
+
|
433
|
+
if message.content == '/google':
|
434
|
+
|
435
|
+
ModeFlag = 1
|
436
|
+
|
437
|
+
await message.channel.send('検索するワードをチャットで発言してね')
|
438
|
+
|
439
|
+
# 単純な応答
|
440
|
+
|
441
|
+
if message.content == 'bot君いる?':
|
442
|
+
|
443
|
+
await message.channel.send('私bot君。あなたの後ろにいるよ。')
|
444
|
+
|
445
|
+
# 特定の文字から始まる文章が発言されたとき
|
446
|
+
|
447
|
+
if message.content.startswith('負け'):
|
448
|
+
|
449
|
+
lose = message.author.name + "の負け!w"
|
450
|
+
|
451
|
+
await message.channel.send(lose)
|
452
|
+
|
453
|
+
#リプライを受け取った時
|
454
|
+
|
455
|
+
if client.user in message.mentions:
|
456
|
+
|
457
|
+
reply = f'{message.author.mention} うるさいよ。'
|
458
|
+
|
459
|
+
await message.channel.send(reply)
|
460
|
+
|
461
|
+
# これについては触れないよ。
|
462
|
+
|
463
|
+
if message.content.startswith("なんだかんだ"):
|
464
|
+
|
465
|
+
kanda = "かんだ・・・神田ァ!?\n" + "https://www.youtube.com/watch?v=KUwpssJX37M"
|
466
|
+
|
467
|
+
await message.channel.send(kanda)
|
468
468
|
|
469
469
|
|
470
470
|
|
2
文法修正
test
CHANGED
@@ -108,23 +108,23 @@
|
|
108
108
|
|
109
109
|
|
110
110
|
|
111
|
-
|
111
|
+
while True:
|
112
|
-
|
112
|
+
|
113
|
-
|
113
|
+
# ここから30秒間隔の処理
|
114
|
-
|
114
|
+
|
115
|
-
|
115
|
+
if last_clocked_time.hour is not datetime.datetime.now().hour:
|
116
|
-
|
116
|
+
|
117
|
-
|
117
|
+
# 2時に強制退出
|
118
|
-
|
118
|
+
|
119
|
-
|
119
|
+
if datetime.datetime.now().hour == 4:
|
120
|
-
|
120
|
+
|
121
|
-
|
121
|
+
print("強制退出を実行します")
|
122
|
-
|
122
|
+
|
123
|
-
|
123
|
+
await move_to_none()
|
124
|
-
|
124
|
+
|
125
|
-
|
125
|
+
last_clocked_time = datetime.datetime.now() # 時刻更新処理
|
126
|
-
|
126
|
+
|
127
|
-
|
127
|
+
await asyncio.sleep(30)
|
128
128
|
|
129
129
|
|
130
130
|
|
1
追記
test
CHANGED
@@ -479,3 +479,5 @@
|
|
479
479
|
おそらくこれで一応動くかと。
|
480
480
|
|
481
481
|
もし動かなかったりエラーが出たらまた教えてください。
|
482
|
+
|
483
|
+
使ったことのないライブラリなどが結構多いので、記法的に問題のあるところを直しておきました。
|