質問編集履歴
4
文法の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,40 +15,41 @@
|
|
15
15
|
なし
|
16
16
|
```
|
17
17
|
```ここに言語を入力
|
18
|
-
#coding:UTF-8
|
18
|
+
# coding:UTF-8
|
19
19
|
import discord
|
20
20
|
from discord.ext import tasks
|
21
21
|
|
22
22
|
TOKEN = "トークン"
|
23
|
-
CHANNEL_ID =
|
23
|
+
CHANNEL_ID =チャンネルID
|
24
24
|
# 接続に必要なオブジェクトを生成
|
25
25
|
client = discord.Client()
|
26
26
|
|
27
|
+
|
27
28
|
@client.event
|
28
29
|
async def on_message(message):
|
29
|
-
#Botだった場合は、return
|
30
|
+
# Botだった場合は、return
|
30
31
|
if message.author.bot:
|
31
32
|
return
|
32
33
|
if message.content == '!start':
|
33
|
-
await message.channel.send('!d bump')
|
34
34
|
|
35
|
-
# 3秒に一回ループ
|
35
|
+
# 3秒に一回ループ
|
36
|
-
|
36
|
+
@tasks.loop(seconds=1)
|
37
|
-
|
37
|
+
async def loop():
|
38
|
-
|
38
|
+
# botが起動するまで待つ
|
39
|
-
|
39
|
+
await client.wait_until_ready()
|
40
|
-
|
40
|
+
channel = client.get_channel(CHANNEL_ID)
|
41
|
-
|
41
|
+
await channel.send('!d bump')
|
42
42
|
|
43
|
-
|
43
|
+
# ループ処理実行
|
44
|
-
|
44
|
+
loop.start()
|
45
45
|
|
46
|
-
|
46
|
+
@client.event
|
47
|
-
|
47
|
+
async def on_message(message):
|
48
|
-
|
48
|
+
if message.content == '!bye':
|
49
|
-
|
49
|
+
await message.channel.send("ばいばーい!")
|
50
|
-
|
50
|
+
loop.stop()
|
51
51
|
|
52
|
+
|
52
53
|
# Botの起動とDiscordサーバーへの接続
|
53
54
|
client.run("Botのトークン")
|
54
55
|
```
|
@@ -57,7 +58,7 @@
|
|
57
58
|
### 試したこと
|
58
59
|
|
59
60
|
インデントエラーが出ていましたが、なんとか修正できました。
|
60
|
-
await client.logout()をloop.stop()にしたら、ボット事態は
|
61
|
+
await client.logout()をloop.stop()にしたら、チャットを送るのを停止し、ボット事態は
|
61
62
|
オンラインを維持できてましたが、!startと打っても再開ができなかったです。
|
62
63
|
|
63
64
|
|
3
試したことの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,9 +12,7 @@
|
|
12
12
|
|
13
13
|
```
|
14
14
|
エラーメッセージ
|
15
|
-
@tasks.loop(seconds=10)
|
16
|
-
|
15
|
+
なし
|
17
|
-
IndentationError: expected an indented block
|
18
16
|
```
|
19
17
|
```ここに言語を入力
|
20
18
|
#coding:UTF-8
|
@@ -59,6 +57,8 @@
|
|
59
57
|
### 試したこと
|
60
58
|
|
61
59
|
インデントエラーが出ていましたが、なんとか修正できました。
|
60
|
+
await client.logout()をloop.stop()にしたら、ボット事態は
|
61
|
+
オンラインを維持できてましたが、!startと打っても再開ができなかったです。
|
62
62
|
|
63
63
|
|
64
64
|
### 補足情報(FW/ツールのバージョンなど)
|
2
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,84 +6,60 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
### 発生している問題・エラーメッセージ
|
9
|
-
|
9
|
+
起動するときになぜか2回、発言してしまいます。
|
10
|
+
終了するときに停止処理をするとログアウトして、再開ができません。
|
11
|
+
await client.logout()が原因だと思うのですが、一時停止のコマンドがわからないです。
|
12
|
+
|
10
13
|
```
|
11
14
|
エラーメッセージ
|
12
15
|
@tasks.loop(seconds=10)
|
13
16
|
^
|
14
17
|
IndentationError: expected an indented block
|
15
|
-
|
16
18
|
```
|
17
|
-
ソースコード
|
18
|
-
|
19
|
+
```ここに言語を入力
|
19
20
|
#coding:UTF-8
|
20
21
|
import discord
|
21
22
|
from discord.ext import tasks
|
22
23
|
|
23
24
|
TOKEN = "トークン"
|
24
|
-
CHANNEL_ID =
|
25
|
+
CHANNEL_ID = チャンネルID
|
26
|
+
# 接続に必要なオブジェクトを生成
|
25
|
-
client = discord.Client()
|
27
|
+
client = discord.Client()
|
26
28
|
|
27
29
|
@client.event
|
28
30
|
async def on_message(message):
|
29
|
-
|
31
|
+
#Botだった場合は、return
|
30
|
-
if message.author.bot:
|
32
|
+
if message.author.bot:
|
31
33
|
return
|
32
34
|
if message.content == '!start':
|
35
|
+
await message.channel.send('!d bump')
|
33
36
|
|
37
|
+
# 3秒に一回ループ
|
38
|
+
@tasks.loop(minutes=1)
|
39
|
+
async def loop():
|
40
|
+
# botが起動するまで待つ
|
41
|
+
await client.wait_until_ready()
|
42
|
+
channel = client.get_channel(CHANNEL_ID)
|
43
|
+
await channel.send('!d bump')
|
34
44
|
|
35
|
-
|
45
|
+
#ループ処理実行
|
36
|
-
|
46
|
+
loop.start()
|
37
|
-
|
38
|
-
await client.wait_until_ready() # botが起動するまで待つ
|
39
|
-
channel = client.get_channel(CHANNEL_ID)
|
40
|
-
await channel.send('!d bump')
|
41
47
|
|
42
|
-
|
43
|
-
loop.start() #ループ処理実行
|
44
|
-
|
45
|
-
@client.event
|
48
|
+
@client.event
|
46
|
-
async def on_message(message):
|
49
|
+
async def on_message(message):
|
47
|
-
|
50
|
+
if message.content == '!bye':
|
48
|
-
|
49
51
|
await message.channel.send("ばいばーい!")
|
50
52
|
await client.logout()
|
51
53
|
|
54
|
+
# Botの起動とDiscordサーバーへの接続
|
55
|
+
client.run("Botのトークン")
|
56
|
+
```
|
52
57
|
|
53
|
-
client.run("Botのトークン") # Botの起動とDiscordサーバーへの接続
|
54
58
|
|
55
|
-
|
56
|
-
|
57
59
|
### 試したこと
|
58
60
|
|
59
|
-
ここに問題に対して試したことを記載してください。
|
60
|
-
インデントエラー
|
61
|
+
インデントエラーが出ていましたが、なんとか修正できました。
|
61
|
-
直りませんでした。
|
62
62
|
|
63
|
-
### 補足情報(FW/ツールのバージョンなど)
|
64
|
-
python 3.8.10
|
65
|
-
### 前提・実現したいこと
|
66
63
|
|
67
|
-
ここに質問の内容を詳しく書いてください。
|
68
|
-
(例)PHP(CakePHP)で●●なシステムを作っています。
|
69
|
-
■■な機能を実装中に以下のエラーメッセージが発生しました。
|
70
|
-
|
71
|
-
### 発生している問題・エラーメッセージ
|
72
|
-
|
73
|
-
```
|
74
|
-
エラーメッセージ
|
75
|
-
```
|
76
|
-
|
77
|
-
### 該当のソースコード
|
78
|
-
|
79
|
-
```ここに言語名を入力
|
80
|
-
ソースコード
|
81
|
-
```
|
82
|
-
|
83
|
-
### 試したこと
|
84
|
-
|
85
|
-
ここに問題に対して試したことを記載してください。
|
86
|
-
|
87
64
|
### 補足情報(FW/ツールのバージョンなど)
|
88
|
-
|
89
|
-
|
65
|
+
python 3.8.10
|
1
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,12 +2,15 @@
|
|
2
2
|
|
3
3
|
ここに質問の内容を詳しく書いてください。
|
4
4
|
discord.pyで2時間ごとに一度、発言をさせたいです。
|
5
|
+
今は、試しているところなので、10秒ごとにループさせようと思っています。
|
5
6
|
|
6
7
|
|
7
8
|
### 発生している問題・エラーメッセージ
|
8
9
|
ループに入るときにエラーが出てしまいます。
|
9
10
|
```
|
10
11
|
エラーメッセージ
|
12
|
+
@tasks.loop(seconds=10)
|
13
|
+
^
|
11
14
|
IndentationError: expected an indented block
|
12
15
|
|
13
16
|
```
|
@@ -19,27 +22,26 @@
|
|
19
22
|
|
20
23
|
TOKEN = "トークン"
|
21
24
|
CHANNEL_ID = CHANNEL_ID
|
22
|
-
# 接続に必要なオブジェクトを生成
|
23
|
-
client = discord.Client()
|
25
|
+
client = discord.Client() # 接続に必要なオブジェクトを生成
|
24
26
|
|
25
27
|
@client.event
|
26
28
|
async def on_message(message):
|
27
|
-
|
29
|
+
|
28
|
-
if message.author.bot:
|
30
|
+
if message.author.bot: #Botだった場合は、return
|
29
31
|
return
|
30
32
|
if message.content == '!start':
|
31
33
|
|
32
|
-
|
34
|
+
|
33
|
-
@tasks.loop(seconds=10)
|
35
|
+
@tasks.loop(seconds=10) # 10秒に一回ループ
|
34
36
|
async def loop():
|
35
|
-
|
37
|
+
|
36
|
-
await client.wait_until_ready()
|
38
|
+
await client.wait_until_ready() # botが起動するまで待つ
|
37
39
|
channel = client.get_channel(CHANNEL_ID)
|
38
40
|
await channel.send('!d bump')
|
39
41
|
|
40
|
-
#ループ処理実行
|
41
|
-
loop.start()
|
42
42
|
|
43
|
+
loop.start() #ループ処理実行
|
44
|
+
|
43
45
|
@client.event
|
44
46
|
async def on_message(message):
|
45
47
|
if "!stop" in message.content:
|
@@ -47,11 +49,11 @@
|
|
47
49
|
await message.channel.send("ばいばーい!")
|
48
50
|
await client.logout()
|
49
51
|
|
50
|
-
# Botの起動とDiscordサーバーへの接続
|
51
|
-
client.run("Botのトークン")
|
52
52
|
|
53
|
+
client.run("Botのトークン") # Botの起動とDiscordサーバーへの接続
|
53
54
|
|
54
55
|
|
56
|
+
|
55
57
|
### 試したこと
|
56
58
|
|
57
59
|
ここに問題に対して試したことを記載してください。
|