質問編集履歴
2
Heroku、Config Vars の設定
test
CHANGED
File without changes
|
test
CHANGED
@@ -123,3 +123,9 @@
|
|
123
123
|
Error: Process completed with exit code 1.
|
124
124
|
|
125
125
|
```
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
###HerokuのConfig Vars の設定
|
130
|
+
|
131
|
+

|
1
回答のソースコードを基に補正したもの
test
CHANGED
File without changes
|
test
CHANGED
@@ -35,3 +35,91 @@
|
|
35
35
|
これらを使ってメッセージを読み込むと役職付与する事が、DM内で出来るかどうか...
|
36
36
|
|
37
37
|
**DMにこだわらなくても匿名で出来るのであれば教えてください**
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
### 補正したソースコード
|
42
|
+
|
43
|
+
下記の回答を基に組んだソースコード
|
44
|
+
|
45
|
+
```Python
|
46
|
+
|
47
|
+
import discord
|
48
|
+
|
49
|
+
from discord.ext.commands import Bot
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
# discord.ext.commands.Botはdiscord.Clientのサブクラスなので
|
56
|
+
|
57
|
+
# discord.Clientのメソッド(get_guild()とか)も使える
|
58
|
+
|
59
|
+
bot = Bot(command_prefix='?')
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
GUILD_ID = 0
|
64
|
+
|
65
|
+
ROLE_ID = 0
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
role = None
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
@bot.event
|
78
|
+
|
79
|
+
async def on_ready():
|
80
|
+
|
81
|
+
guild = bot.get_guild(GUILD_ID)
|
82
|
+
|
83
|
+
role = guild.get_role(ROLE_ID)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
@bot.command(name='r')
|
90
|
+
|
91
|
+
async def add_role(ctx, word):
|
92
|
+
|
93
|
+
if (role is not None
|
94
|
+
|
95
|
+
and isinstance(ctx.message.channel, discord.DMChannel)
|
96
|
+
|
97
|
+
and word == 'ラーメン大好き'):
|
98
|
+
|
99
|
+
await ctx.message.author.add_roles(role)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
bot.run('TOKEN')
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
###補正したソースコードのエラーコード
|
112
|
+
|
113
|
+
```Pyhton
|
114
|
+
|
115
|
+
Run flake8 --ignore=E302,E501
|
116
|
+
|
117
|
+
./discordbot.py:19:5: F841 local variable 'role' is assigned to but never used
|
118
|
+
|
119
|
+
./discordbot.py:25:9: W503 line break before binary operator
|
120
|
+
|
121
|
+
./discordbot.py:26:13: W503 line break before binary operator
|
122
|
+
|
123
|
+
Error: Process completed with exit code 1.
|
124
|
+
|
125
|
+
```
|