質問編集履歴
2
Heroku、Config Vars の設定
title
CHANGED
File without changes
|
body
CHANGED
@@ -60,4 +60,7 @@
|
|
60
60
|
./discordbot.py:25:9: W503 line break before binary operator
|
61
61
|
./discordbot.py:26:13: W503 line break before binary operator
|
62
62
|
Error: Process completed with exit code 1.
|
63
|
-
```
|
63
|
+
```
|
64
|
+
|
65
|
+
###HerokuのConfig Vars の設定
|
66
|
+

|
1
回答のソースコードを基に補正したもの
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,4 +16,48 @@
|
|
16
16
|
await user.add_roles(role)
|
17
17
|
```
|
18
18
|
これらを使ってメッセージを読み込むと役職付与する事が、DM内で出来るかどうか...
|
19
|
-
**DMにこだわらなくても匿名で出来るのであれば教えてください**
|
19
|
+
**DMにこだわらなくても匿名で出来るのであれば教えてください**
|
20
|
+
|
21
|
+
### 補正したソースコード
|
22
|
+
下記の回答を基に組んだソースコード
|
23
|
+
```Python
|
24
|
+
import discord
|
25
|
+
from discord.ext.commands import Bot
|
26
|
+
|
27
|
+
|
28
|
+
# discord.ext.commands.Botはdiscord.Clientのサブクラスなので
|
29
|
+
# discord.Clientのメソッド(get_guild()とか)も使える
|
30
|
+
bot = Bot(command_prefix='?')
|
31
|
+
|
32
|
+
GUILD_ID = 0
|
33
|
+
ROLE_ID = 0
|
34
|
+
|
35
|
+
|
36
|
+
role = None
|
37
|
+
|
38
|
+
|
39
|
+
@bot.event
|
40
|
+
async def on_ready():
|
41
|
+
guild = bot.get_guild(GUILD_ID)
|
42
|
+
role = guild.get_role(ROLE_ID)
|
43
|
+
|
44
|
+
|
45
|
+
@bot.command(name='r')
|
46
|
+
async def add_role(ctx, word):
|
47
|
+
if (role is not None
|
48
|
+
and isinstance(ctx.message.channel, discord.DMChannel)
|
49
|
+
and word == 'ラーメン大好き'):
|
50
|
+
await ctx.message.author.add_roles(role)
|
51
|
+
|
52
|
+
|
53
|
+
bot.run('TOKEN')
|
54
|
+
```
|
55
|
+
|
56
|
+
###補正したソースコードのエラーコード
|
57
|
+
```Pyhton
|
58
|
+
Run flake8 --ignore=E302,E501
|
59
|
+
./discordbot.py:19:5: F841 local variable 'role' is assigned to but never used
|
60
|
+
./discordbot.py:25:9: W503 line break before binary operator
|
61
|
+
./discordbot.py:26:13: W503 line break before binary operator
|
62
|
+
Error: Process completed with exit code 1.
|
63
|
+
```
|