質問編集履歴

1

2021/09/27 15:38

投稿

watn
watn

スコア0

test CHANGED
File without changes
test CHANGED
@@ -46,9 +46,131 @@
46
46
 
47
47
  ```
48
48
 
49
+
50
+
51
+ @bot.event()
52
+
49
- async def up1(ctx):
53
+ async def on_add_reaction(payload):
54
+
50
-
55
+ if payload.channel_id != CHANNEL_ID4:
56
+
57
+ return
58
+
59
+ else:
60
+
61
+ if payload.emoji.neme != EMOJI_1 or EMOJI_2 or EMOJI_3:
62
+
63
+ return
64
+
65
+ else:
66
+
67
+ if payload.emoji.neme == EMOJI_1:
68
+
51
- channel = bot.get_channel(CHANNEL_ID1)
69
+ channel = bot.get_channel(CHANNEL_ID1)
70
+
71
+ await channel.send('xxxxx')
72
+
73
+ else:
74
+
75
+ if payload.emoji.neme == EMOJI_2:
76
+
77
+ channel = bot.get_channel(CHANNEL_ID2)
78
+
79
+ await channel.send('xxxxx')
80
+
81
+ else:
82
+
83
+ if payload.emoji.neme == EMOJI_3:
84
+
85
+ channel = bot.get_channel(CHANNEL_ID3)
86
+
87
+ await channel.send('xxxxx')
88
+
89
+ return
90
+
91
+
92
+
93
+
94
+
95
+ token = getenv('DISCORD_BOT_TOKEN')
96
+
97
+ bot.run(token)
98
+
99
+ ```
100
+
101
+
102
+
103
+ ### ソースコード
104
+
105
+ ```python
106
+
107
+ import discord
108
+
109
+ from discord.ext import commands
110
+
111
+ from os import getenv
112
+
113
+ import traceback
114
+
115
+
116
+
117
+
118
+
119
+ bot = commands.Bot(command_prefix='/')
120
+
121
+
122
+
123
+
124
+
125
+ CHANNEL_ID1 = 0123456789
126
+
127
+ CHANNEL_ID2 = 0123456789
128
+
129
+ CHANNEL_ID3 = 0123456789
130
+
131
+ CHANNEL_ID4 = 0123456789
132
+
133
+ EMOJI_1 = "<:xxx:0123456789>"
134
+
135
+ EMOJI_2 = "<:xxx:0123456789>"
136
+
137
+ EMOJI_3 = "<:xxx:0123456789>"
138
+
139
+ EMOJI_4 = "<:xxx:0123456789>"
140
+
141
+
142
+
143
+ @bot.event
144
+
145
+ async def on_command_error(ctx, error):
146
+
147
+ orig_error = getattr(error, "original", error)
148
+
149
+ error_msg = ''.join(traceback.TracebackException.from_exception(orig_error).format())
150
+
151
+ await ctx.send(error_msg)
152
+
153
+
154
+
155
+
156
+
157
+ @bot.command()
158
+
159
+ async def ping(ctx):
160
+
161
+ await ctx.send('pong')
162
+
163
+
164
+
165
+
166
+
167
+ @bot.event #BOTが接続したら任意のメッセージを任意のチャンネルで発言する
168
+
169
+ async def on_ready():
170
+
171
+ await bot.change_presence(activity=discord.Game(name="ピポピポ", type=1))
172
+
173
+ channel = bot.get_channel(CHANNEL_ID4)
52
174
 
53
175
  await channel.send('xxxxx')
54
176
 
@@ -56,9 +178,11 @@
56
178
 
57
179
 
58
180
 
181
+ @bot.command()
182
+
59
- async def up2(ctx):
183
+ async def ready(ctx):
60
-
184
+
61
- channel = bot.get_channel(CHANNEL_ID2)
185
+ channel = bot.get_channel(CHANNEL_ID4)
62
186
 
63
187
  await channel.send('xxxxx')
64
188
 
@@ -66,16 +190,6 @@
66
190
 
67
191
 
68
192
 
69
- async def up3(ctx):
70
-
71
- channel = bot.get_channel(CHANNEL_ID3)
72
-
73
- await channel.send('xxxxx')
74
-
75
-
76
-
77
-
78
-
79
193
  @bot.event()
80
194
 
81
195
  async def on_add_reaction(payload):
@@ -128,148 +242,6 @@
128
242
 
129
243
 
130
244
 
131
- ### ソースコード
132
-
133
- ```python
134
-
135
- import discord
136
-
137
- from discord.ext import commands
138
-
139
- from os import getenv
140
-
141
- import traceback
142
-
143
-
144
-
145
-
146
-
147
- bot = commands.Bot(command_prefix='/')
148
-
149
-
150
-
151
-
152
-
153
- CHANNEL_ID1 = 0123456789
154
-
155
- CHANNEL_ID2 = 0123456789
156
-
157
- CHANNEL_ID3 = 0123456789
158
-
159
- CHANNEL_ID4 = 0123456789
160
-
161
- EMOJI_1 = "<:xxx:0123456789>"
162
-
163
- EMOJI_2 = "<:xxx:0123456789>"
164
-
165
- EMOJI_3 = "<:xxx:0123456789>"
166
-
167
- EMOJI_4 = "<:xxx:0123456789>"
168
-
169
-
170
-
171
- @bot.event
172
-
173
- async def on_command_error(ctx, error):
174
-
175
- orig_error = getattr(error, "original", error)
176
-
177
- error_msg = ''.join(traceback.TracebackException.from_exception(orig_error).format())
178
-
179
- await ctx.send(error_msg)
180
-
181
-
182
-
183
-
184
-
185
- @bot.command()
186
-
187
- async def ping(ctx):
188
-
189
- await ctx.send('pong')
190
-
191
-
192
-
193
-
194
-
195
- @bot.event #BOTが接続したら任意のメッセージを任意のチャンネルで発言する
196
-
197
- async def on_ready():
198
-
199
- await bot.change_presence(activity=discord.Game(name="ピポピポ", type=1))
200
-
201
- channel = bot.get_channel(CHANNEL_ID4)
202
-
203
- await channel.send('xxxxx')
204
-
205
-
206
-
207
-
208
-
209
- @bot.command()
210
-
211
- async def ready(ctx):
212
-
213
- channel = bot.get_channel(CHANNEL_ID4)
214
-
215
- await channel.send('xxxxx')
216
-
217
-
218
-
219
-
220
-
221
- @bot.event()
222
-
223
- async def on_add_reaction(payload):
224
-
225
- if payload.channel_id != CHANNEL_ID4:
226
-
227
- return
228
-
229
- else:
230
-
231
- if payload.emoji.neme != EMOJI_1 or EMOJI_2 or EMOJI_3:
232
-
233
- return
234
-
235
- else:
236
-
237
- if payload.emoji.neme == EMOJI_1:
238
-
239
- channel = bot.get_channel(CHANNEL_ID1)
240
-
241
- await channel.send('xxxxx')
242
-
243
- else:
244
-
245
- if payload.emoji.neme == EMOJI_2:
246
-
247
- channel = bot.get_channel(CHANNEL_ID2)
248
-
249
- await channel.send('xxxxx')
250
-
251
- else:
252
-
253
- if payload.emoji.neme == EMOJI_3:
254
-
255
- channel = bot.get_channel(CHANNEL_ID3)
256
-
257
- await channel.send('xxxxx')
258
-
259
- return
260
-
261
-
262
-
263
-
264
-
265
- token = getenv('DISCORD_BOT_TOKEN')
266
-
267
- bot.run(token)
268
-
269
- ```
270
-
271
-
272
-
273
245
  ### 試したこと
274
246
 
275
247