質問編集履歴
13
情報追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -147,8 +147,28 @@
|
|
147
147
|
bot.add_cog(LibeCog(bot))
|
148
148
|
|
149
149
|
```
|
150
|
+
実行結果
|
151
|
+
```
|
152
|
+
Traceback (most recent call last):
|
153
|
+
File "E:\root\main.py", line 25, in __init__
|
154
|
+
self.load_extension(cog)
|
155
|
+
File "C:\Users\my_pc\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 676, in load_extension
|
156
|
+
raise errors.ExtensionNotFound(name)
|
157
|
+
discord.ext.commands.errors.ExtensionNotFound: Extension 'cogs.cogs' could not be loaded.
|
158
|
+
--------------------------------------
|
159
|
+
Logged on
|
160
|
+
-------------------------------------
|
161
|
+
bot#name
|
162
|
+
--------------------------------------
|
163
|
+
845449538545909791
|
164
|
+
-------------------------------------
|
165
|
+
ログインしました。
|
166
|
+
-------------------------------------
|
167
|
+
2021-10-04
|
168
|
+
--------------------------------------
|
169
|
+
```
|
170
|
+
です
|
150
171
|
|
151
|
-
|
152
172
|
開発環境
|
153
173
|
```
|
154
174
|
discord.py 1.7.3
|
12
情報追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,20 +4,18 @@
|
|
4
4
|
root
|
5
5
|
|
|
6
6
|
|- cogs|
|
7
|
-
| └
|
7
|
+
| └ LibeCog.py
|
8
8
|
main.py
|
9
9
|
|
10
10
|
```
|
11
11
|
また出ているエラーコード
|
12
12
|
```
|
13
13
|
Traceback (most recent call last):
|
14
|
-
File "main.py", line 25, in __init__
|
14
|
+
File "E:\root\main.py", line 25, in __init__
|
15
15
|
self.load_extension(cog)
|
16
|
-
File "
|
16
|
+
File "C:\Users\my_pc\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 676, in load_extension
|
17
|
-
|
17
|
+
raise errors.ExtensionNotFound(name)
|
18
|
-
|
18
|
+
discord.ext.commands.errors.ExtensionNotFound: Extension 'cogs.cogs' could not be loaded.
|
19
|
-
parent = __import__(parent_name, fromlist=['__path__'])
|
20
|
-
ModuleNotFoundError: No module named 'cogs'
|
21
19
|
```
|
22
20
|
|
23
21
|
|
11
情報更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
```
|
3
3
|
main.py
|
4
4
|
root
|
5
|
-
|
5
|
+
|
|
6
|
-
cogs
|
6
|
+
|- cogs|
|
7
|
-
└ cogs.py
|
7
|
+
| └ cogs.py
|
8
|
+
main.py
|
9
|
+
|
8
10
|
```
|
9
11
|
また出ているエラーコード
|
10
12
|
```
|
@@ -20,7 +22,7 @@
|
|
20
22
|
|
21
23
|
|
22
24
|
main.py
|
23
|
-
```
|
25
|
+
```python
|
24
26
|
from discord.ext import commands # Bot Commands Frameworkをインポート
|
25
27
|
|
26
28
|
import traceback
|
@@ -28,18 +30,14 @@
|
|
28
30
|
from datetime import datetime, timedelta
|
29
31
|
import datetime
|
30
32
|
|
33
|
+
INITIAL_EXTENSIONS = ['cogs.cogs'
|
34
|
+
]
|
35
|
+
|
31
36
|
now = datetime.datetime.now()
|
32
37
|
|
33
|
-
INITIAL_EXTENSIONS = [
|
34
|
-
'cogs.cogs'
|
35
|
-
]
|
36
|
-
|
37
38
|
# コグとして用いるクラスを定義。
|
38
39
|
|
39
|
-
#ここの部分はtextファイルに残してるよ
|
40
40
|
|
41
|
-
line25行はここです
|
42
|
-
-------------------------------------------------------
|
43
41
|
class LibeBot(commands.Bot):
|
44
42
|
def __init__(self, command_prefix):
|
45
43
|
# スーパークラスのコンストラクタに値を渡して実行。
|
@@ -52,8 +50,8 @@
|
|
52
50
|
self.load_extension(cog)
|
53
51
|
except Exception:
|
54
52
|
traceback.print_exc()
|
55
|
-
---------------------------------------------------------
|
56
53
|
|
54
|
+
|
57
55
|
async def on_ready(self):
|
58
56
|
print('--------------------------------------')
|
59
57
|
print('Logged on as {0}!'.format(self.user))
|
@@ -68,14 +66,13 @@
|
|
68
66
|
print('--------------------------------------')
|
69
67
|
|
70
68
|
|
71
|
-
|
72
69
|
if __name__ == '__main__':
|
73
|
-
bot = LibeBot(command_prefix='.')
|
70
|
+
bot = LibeBot(command_prefix='.')
|
74
71
|
bot.run('TOKEN')
|
75
72
|
|
76
73
|
```
|
77
74
|
一様Cogファイルも書いておきます
|
78
|
-
```
|
75
|
+
```python
|
79
76
|
import discord
|
80
77
|
import logging
|
81
78
|
import abc
|
@@ -99,36 +96,16 @@
|
|
99
96
|
now = datetime.datetime.now()
|
100
97
|
|
101
98
|
intents = discord.Intents.all()
|
102
|
-
削除済み
|
103
|
-
------------------------------------------------------------------
|
104
|
-
bot = commands.Bot(command_prefix='.',
|
105
|
-
description='A bot that greets the user back.')
|
106
|
-
---------------------------------------------------------------------
|
107
99
|
|
100
|
+
|
101
|
+
|
108
102
|
# コグとして用いるクラスを定義。
|
109
103
|
class LibeCog(commands.Cog):
|
110
104
|
|
111
|
-
ここは削除しました
|
112
|
-
--------------------------------------------------------------------
|
113
|
-
# TestCogクラスのコンストラクタ。Botを受取り、インスタンス変数として保持。
|
114
|
-
def __init__(self, bot):
|
115
|
-
self.bot = bot
|
116
|
-
--------------------------------------------------------------------
|
117
105
|
|
118
|
-
|
119
|
-
# コマンドの作成。コマンドはcommandデコレータで必ず修飾する。
|
120
106
|
@commands.command()
|
121
107
|
async def ping(self, ctx):
|
122
108
|
await ctx.send('pong!')
|
123
|
-
ここも削除しました
|
124
|
-
--------------------------------------------------------------
|
125
|
-
@bot.commad()
|
126
|
-
@commands.has_role('Mastar')
|
127
|
-
async def purge(ctx, target: int):
|
128
|
-
channel = ctx.message.channel
|
129
|
-
deleted = await channel.purge(limit=target)
|
130
|
-
await ctx.send(f"{len(deleted)})メッセージを削除しました。")
|
131
|
-
-------------------------------------------------------------
|
132
109
|
|
133
110
|
@commands.Cog.listener()
|
134
111
|
async def on_message(self, message):
|
@@ -143,10 +120,8 @@
|
|
143
120
|
if message.content.startswith('/id'):
|
144
121
|
await message.channel.send('PaL_Libe')
|
145
122
|
|
146
|
-
if message.content.startswith('logout'):
|
147
|
-
await message.channel.send('```ログアウトします。```')
|
148
|
-
await LibeCog.logout()
|
149
123
|
|
124
|
+
|
150
125
|
if message.content == '!bot':
|
151
126
|
await message.channel.send('```BOT discordバージョン起動中です。```')
|
152
127
|
|
@@ -170,7 +145,9 @@
|
|
170
145
|
|
171
146
|
|
172
147
|
def setup(bot):
|
148
|
+
print('load extension.')
|
173
149
|
bot.add_cog(LibeCog(bot))
|
150
|
+
|
174
151
|
```
|
175
152
|
|
176
153
|
|
10
情報追加.情報修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,21 +17,7 @@
|
|
17
17
|
parent = __import__(parent_name, fromlist=['__path__'])
|
18
18
|
ModuleNotFoundError: No module named 'cogs'
|
19
19
|
```
|
20
|
-
line 28番のコードはこれです
|
21
|
-
```
|
22
|
-
class LibeBot(commands.Bot):
|
23
|
-
def __init__(self, command_prefix):
|
24
|
-
# スーパークラスのコンストラクタに値を渡して実行。
|
25
|
-
super().__init__(command_prefix)
|
26
20
|
|
27
|
-
# INITIAL_COGSに格納されている名前から、コグを読み込む。
|
28
|
-
# エラーが発生した場合は、エラー内容を表示。
|
29
|
-
for cog in INITIAL_EXTENSIONS:
|
30
|
-
try:
|
31
|
-
self.load_extension(cog)
|
32
|
-
except Exception:
|
33
|
-
traceback.print_exc()
|
34
|
-
```
|
35
21
|
|
36
22
|
main.py
|
37
23
|
```
|
@@ -52,7 +38,8 @@
|
|
52
38
|
|
53
39
|
#ここの部分はtextファイルに残してるよ
|
54
40
|
|
55
|
-
|
41
|
+
line25行はここです
|
42
|
+
-------------------------------------------------------
|
56
43
|
class LibeBot(commands.Bot):
|
57
44
|
def __init__(self, command_prefix):
|
58
45
|
# スーパークラスのコンストラクタに値を渡して実行。
|
@@ -65,8 +52,8 @@
|
|
65
52
|
self.load_extension(cog)
|
66
53
|
except Exception:
|
67
54
|
traceback.print_exc()
|
55
|
+
---------------------------------------------------------
|
68
56
|
|
69
|
-
|
70
57
|
async def on_ready(self):
|
71
58
|
print('--------------------------------------')
|
72
59
|
print('Logged on as {0}!'.format(self.user))
|
9
情報追加.情報修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,13 +6,7 @@
|
|
6
6
|
cogs
|
7
7
|
└ cogs.py
|
8
8
|
```
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
出ている
|
9
|
+
また出ているエラーコード
|
16
10
|
```
|
17
11
|
Traceback (most recent call last):
|
18
12
|
File "main.py", line 25, in __init__
|
@@ -118,9 +112,11 @@
|
|
118
112
|
now = datetime.datetime.now()
|
119
113
|
|
120
114
|
intents = discord.Intents.all()
|
121
|
-
|
115
|
+
削除済み
|
116
|
+
------------------------------------------------------------------
|
122
117
|
bot = commands.Bot(command_prefix='.',
|
123
118
|
description='A bot that greets the user back.')
|
119
|
+
---------------------------------------------------------------------
|
124
120
|
|
125
121
|
# コグとして用いるクラスを定義。
|
126
122
|
class LibeCog(commands.Cog):
|
8
情報追加.情報修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -51,7 +51,7 @@
|
|
51
51
|
now = datetime.datetime.now()
|
52
52
|
|
53
53
|
INITIAL_EXTENSIONS = [
|
54
|
-
'cogs.
|
54
|
+
'cogs.cogs'
|
55
55
|
]
|
56
56
|
|
57
57
|
# コグとして用いるクラスを定義。
|
7
情報追加.情報修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,10 +12,10 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
出ているエラーコード
|
15
|
+
出ている新しい?エラーコード
|
16
16
|
```
|
17
17
|
Traceback (most recent call last):
|
18
|
-
File "main.py", line
|
18
|
+
File "main.py", line 25, in __init__
|
19
19
|
self.load_extension(cog)
|
20
20
|
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 674, in load_extension
|
21
21
|
spec = importlib.util.find_spec(name)
|
@@ -137,13 +137,15 @@
|
|
137
137
|
@commands.command()
|
138
138
|
async def ping(self, ctx):
|
139
139
|
await ctx.send('pong!')
|
140
|
-
|
140
|
+
ここも削除しました
|
141
|
+
--------------------------------------------------------------
|
141
142
|
@bot.commad()
|
142
143
|
@commands.has_role('Mastar')
|
143
144
|
async def purge(ctx, target: int):
|
144
145
|
channel = ctx.message.channel
|
145
146
|
deleted = await channel.purge(limit=target)
|
146
147
|
await ctx.send(f"{len(deleted)})メッセージを削除しました。")
|
148
|
+
-------------------------------------------------------------
|
147
149
|
|
148
150
|
@commands.Cog.listener()
|
149
151
|
async def on_message(self, message):
|
6
情報修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
出ているエラーコード
|
16
16
|
```
|
17
17
|
Traceback (most recent call last):
|
18
|
-
File "main.py", line
|
18
|
+
File "main.py", line 24, in __init__
|
19
19
|
self.load_extension(cog)
|
20
20
|
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 674, in load_extension
|
21
21
|
spec = importlib.util.find_spec(name)
|
@@ -125,10 +125,14 @@
|
|
125
125
|
# コグとして用いるクラスを定義。
|
126
126
|
class LibeCog(commands.Cog):
|
127
127
|
|
128
|
+
ここは削除しました
|
129
|
+
--------------------------------------------------------------------
|
128
130
|
# TestCogクラスのコンストラクタ。Botを受取り、インスタンス変数として保持。
|
129
131
|
def __init__(self, bot):
|
130
132
|
self.bot = bot
|
133
|
+
--------------------------------------------------------------------
|
131
134
|
|
135
|
+
|
132
136
|
# コマンドの作成。コマンドはcommandデコレータで必ず修飾する。
|
133
137
|
@commands.command()
|
134
138
|
async def ping(self, ctx):
|
5
情報追加.情報修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -189,4 +189,5 @@
|
|
189
189
|
```
|
190
190
|
discord.py 1.7.3
|
191
191
|
python 3.8.12
|
192
|
-
```
|
192
|
+
```
|
193
|
+
良ければアビリティを表示するコードを教えてくれたら幸いです
|
4
情報追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
ディレクトリ構成
|
2
|
+
```
|
3
|
+
main.py
|
4
|
+
root
|
5
|
+
|
|
6
|
+
cogs
|
7
|
+
└ cogs.py
|
8
|
+
```
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
1
15
|
出ているエラーコード
|
2
16
|
```
|
3
17
|
Traceback (most recent call last):
|
3
情報追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -79,8 +79,100 @@
|
|
79
79
|
bot.run('TOKEN')
|
80
80
|
|
81
81
|
```
|
82
|
+
一様Cogファイルも書いておきます
|
83
|
+
```
|
84
|
+
import discord
|
85
|
+
import logging
|
86
|
+
import abc
|
87
|
+
import requests
|
88
|
+
from discord.ext import tasks, commands
|
89
|
+
import aiohttp
|
90
|
+
from pprint import pprint
|
91
|
+
import asyncio
|
92
|
+
import json
|
93
|
+
import typing
|
94
|
+
import traceback
|
95
|
+
import random
|
96
|
+
import traceback
|
97
|
+
import time
|
98
|
+
import re
|
99
|
+
import traceback
|
100
|
+
from discord.ext import commands
|
101
|
+
from datetime import datetime, timedelta
|
102
|
+
import datetime
|
82
103
|
|
104
|
+
now = datetime.datetime.now()
|
105
|
+
|
106
|
+
intents = discord.Intents.all()
|
107
|
+
|
108
|
+
bot = commands.Bot(command_prefix='.',
|
109
|
+
description='A bot that greets the user back.')
|
110
|
+
|
111
|
+
# コグとして用いるクラスを定義。
|
112
|
+
class LibeCog(commands.Cog):
|
113
|
+
|
114
|
+
# TestCogクラスのコンストラクタ。Botを受取り、インスタンス変数として保持。
|
115
|
+
def __init__(self, bot):
|
116
|
+
self.bot = bot
|
117
|
+
|
118
|
+
# コマンドの作成。コマンドはcommandデコレータで必ず修飾する。
|
119
|
+
@commands.command()
|
120
|
+
async def ping(self, ctx):
|
121
|
+
await ctx.send('pong!')
|
122
|
+
|
123
|
+
@bot.commad()
|
124
|
+
@commands.has_role('Mastar')
|
125
|
+
async def purge(ctx, target: int):
|
126
|
+
channel = ctx.message.channel
|
127
|
+
deleted = await channel.purge(limit=target)
|
128
|
+
await ctx.send(f"{len(deleted)})メッセージを削除しました。")
|
129
|
+
|
130
|
+
@commands.Cog.listener()
|
131
|
+
async def on_message(self, message):
|
132
|
+
if message.author.bot:
|
133
|
+
return
|
134
|
+
|
135
|
+
if message.content == 'こんにちは':
|
136
|
+
await message.channel.send('こんにちは')
|
137
|
+
|
138
|
+
print('メッセージが来たよ→ {0.author}: {0.content}'.format(message))
|
139
|
+
|
140
|
+
if message.content.startswith('/id'):
|
141
|
+
await message.channel.send('PaL_Libe')
|
142
|
+
|
143
|
+
if message.content.startswith('logout'):
|
144
|
+
await message.channel.send('```ログアウトします。```')
|
145
|
+
await LibeCog.logout()
|
146
|
+
|
147
|
+
if message.content == '!bot':
|
148
|
+
await message.channel.send('```BOT discordバージョン起動中です。```')
|
149
|
+
|
150
|
+
if message.content.startswith('Hi'):
|
151
|
+
await message.channel.send(message.author.mention + 'こんちゃーす')
|
152
|
+
|
153
|
+
if message.content.startswith('/nhk'):
|
154
|
+
await message.channel.send(
|
155
|
+
message.author.mention +
|
156
|
+
'https://gendai.ismedia.jp/mwimgs/2/7/-/img_27d1ecc00191cbbf4d98e1129f2399f544134.jpg'
|
157
|
+
)
|
158
|
+
|
159
|
+
if message.content.startswith('.'):
|
160
|
+
await message.channel.send(
|
161
|
+
message.author.mention +
|
162
|
+
'https://img.huffingtonpost.com/asset/5c6389752300007601224077.jpeg?ops=1200_630'
|
163
|
+
)
|
164
|
+
|
165
|
+
if message.content.startswith('/日にち'):
|
166
|
+
await message.channel.send(f"```{now.date()}です。```")
|
167
|
+
|
168
|
+
|
169
|
+
def setup(bot):
|
170
|
+
bot.add_cog(LibeCog(bot))
|
171
|
+
```
|
172
|
+
|
173
|
+
|
83
|
-
|
174
|
+
開発環境
|
175
|
+
```
|
84
176
|
discord.py 1.7.3
|
85
177
|
python 3.8.12
|
86
178
|
```
|
2
情報追加.情報修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,8 +25,8 @@
|
|
25
25
|
traceback.print_exc()
|
26
26
|
```
|
27
27
|
|
28
|
-
|
28
|
+
main.py
|
29
|
-
```
|
29
|
+
```
|
30
30
|
from discord.ext import commands # Bot Commands Frameworkをインポート
|
31
31
|
|
32
32
|
import traceback
|
1
情報追加.情報修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
出ているエラーコード
|
2
|
+
```
|
2
3
|
Traceback (most recent call last):
|
3
4
|
File "main.py", line 28, in __init__
|
4
5
|
self.load_extension(cog)
|
@@ -8,7 +9,23 @@
|
|
8
9
|
parent = __import__(parent_name, fromlist=['__path__'])
|
9
10
|
ModuleNotFoundError: No module named 'cogs'
|
10
11
|
```
|
12
|
+
line 28番のコードはこれです
|
13
|
+
```
|
14
|
+
class LibeBot(commands.Bot):
|
15
|
+
def __init__(self, command_prefix):
|
16
|
+
# スーパークラスのコンストラクタに値を渡して実行。
|
17
|
+
super().__init__(command_prefix)
|
11
18
|
|
19
|
+
# INITIAL_COGSに格納されている名前から、コグを読み込む。
|
20
|
+
# エラーが発生した場合は、エラー内容を表示。
|
21
|
+
for cog in INITIAL_EXTENSIONS:
|
22
|
+
try:
|
23
|
+
self.load_extension(cog)
|
24
|
+
except Exception:
|
25
|
+
traceback.print_exc()
|
26
|
+
```
|
27
|
+
|
28
|
+
|
12
29
|
```ここです
|
13
30
|
from discord.ext import commands # Bot Commands Frameworkをインポート
|
14
31
|
|
@@ -66,6 +83,4 @@
|
|
66
83
|
```開発環境
|
67
84
|
discord.py 1.7.3
|
68
85
|
python 3.8.12
|
69
|
-
|
70
|
-
|
71
86
|
```
|