質問編集履歴
5
少し修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
CHANNEL_ID2 =
|
47
|
+
CHANNEL_ID2 = #チャンネルID
|
48
48
|
|
49
49
|
# 接続に必要なオブジェクトを生成
|
50
50
|
|
4
エラー文の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,9 +8,21 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
###
|
11
|
+
### エラー文
|
12
12
|
|
13
|
+
Ignoring exception in on_message
|
14
|
+
|
15
|
+
Traceback (most recent call last):
|
16
|
+
|
17
|
+
File "C:\Users\PycharmProjects\discord\venv\lib\site-packages\discord\client.py", line 343, in _run_event
|
18
|
+
|
13
|
-
|
19
|
+
await coro(*args, **kwargs)
|
20
|
+
|
21
|
+
File "C:\Users\PycharmProjects\discord\bot.py", line 48, in on_message
|
22
|
+
|
23
|
+
jikan = jikan + h
|
24
|
+
|
25
|
+
NameError: name 'channel' is not defined
|
14
26
|
|
15
27
|
|
16
28
|
|
3
回答を基にプログラムを編集。
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,6 +22,26 @@
|
|
22
22
|
|
23
23
|
```Python
|
24
24
|
|
25
|
+
#coding:UTF-8
|
26
|
+
|
27
|
+
import discord
|
28
|
+
|
29
|
+
from discord.ext import tasks
|
30
|
+
|
31
|
+
from datetime import datetime
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
CHANNEL_ID2 = 851720569183141910 #チャンネルID
|
36
|
+
|
37
|
+
# 接続に必要なオブジェクトを生成
|
38
|
+
|
39
|
+
client = discord.Client()
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
25
45
|
@client.event
|
26
46
|
|
27
47
|
async def on_message(message):
|
@@ -34,7 +54,9 @@
|
|
34
54
|
|
35
55
|
number = str.lstrip('/')
|
36
56
|
|
57
|
+
# min = (100 - number) * 10 <-- intに変換
|
58
|
+
|
37
|
-
min = (100 - number) * 10
|
59
|
+
min = (100 - int(number)) * 10
|
38
60
|
|
39
61
|
if min >= 60:
|
40
62
|
|
@@ -42,24 +64,38 @@
|
|
42
64
|
|
43
65
|
minute = min % 60
|
44
66
|
|
45
|
-
|
67
|
+
else:
|
68
|
+
|
69
|
+
hour = 0 # <-- 60以下の場合のhourの初期化
|
46
70
|
|
47
71
|
minute = min
|
48
72
|
|
49
|
-
now = datetime.
|
73
|
+
now = datetime.now()
|
50
74
|
|
51
75
|
jikan = now.hour + hour
|
52
76
|
|
53
77
|
fun = now.minute + minute
|
54
78
|
|
55
|
-
|
79
|
+
if fun >= 60:
|
56
80
|
|
57
|
-
|
81
|
+
h = fun // 60
|
58
82
|
|
59
|
-
|
83
|
+
fun = fun % 60
|
60
84
|
|
61
|
-
|
85
|
+
jikan = jikan + h
|
86
|
+
|
87
|
+
channel = client.get_channel(CHANNEL_ID2)
|
62
88
|
|
63
89
|
await channel.send(str(jikan) + '時' + str(fun) + '分です。')
|
64
90
|
|
91
|
+
|
92
|
+
|
93
|
+
#ループ処理実行
|
94
|
+
|
95
|
+
loop.start()
|
96
|
+
|
97
|
+
# Botの起動とDiscordサーバーへの接続
|
98
|
+
|
99
|
+
client.run(TOKEN)
|
100
|
+
|
65
101
|
```
|
2
インデントに誤りがあったため修正。
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,13 +52,13 @@
|
|
52
52
|
|
53
53
|
fun = now.minute + minute
|
54
54
|
|
55
|
-
if fun >= 60:
|
55
|
+
if fun >= 60:
|
56
56
|
|
57
|
-
h = fun // 60
|
57
|
+
h = fun // 60
|
58
58
|
|
59
|
-
fun = fun % 60
|
59
|
+
fun = fun % 60
|
60
60
|
|
61
|
-
jikan = jikan + h
|
61
|
+
jikan = jikan + h
|
62
62
|
|
63
63
|
await channel.send(str(jikan) + '時' + str(fun) + '分です。')
|
64
64
|
|
1
時間の計算式が間違っていたため修正。
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,12 +42,24 @@
|
|
42
42
|
|
43
43
|
minute = min % 60
|
44
44
|
|
45
|
+
else:
|
46
|
+
|
47
|
+
minute = min
|
48
|
+
|
45
49
|
now = datetime.datetime.now()
|
46
50
|
|
47
51
|
jikan = now.hour + hour
|
48
52
|
|
49
53
|
fun = now.minute + minute
|
50
54
|
|
55
|
+
if fun >= 60:
|
56
|
+
|
57
|
+
h = fun // 60
|
58
|
+
|
59
|
+
fun = fun % 60
|
60
|
+
|
61
|
+
jikan = jikan + h
|
62
|
+
|
51
63
|
await channel.send(str(jikan) + '時' + str(fun) + '分です。')
|
52
64
|
|
53
65
|
```
|