-
Notifications
You must be signed in to change notification settings - Fork 1
/
making-my-own-discord-bots.html
427 lines (339 loc) · 39 KB
/
making-my-own-discord-bots.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Making My Own Discord Bots — OrangeDurito.blog</title>
<meta name="author" content="Chandan Sinha">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/images/logo.png" rel="icon">
<link href="/theme/css/main.css" media="screen, projection"
rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/theme/css/font-awesome/fontawesome-new/css/all.css">
<link rel="stylesheet" type="text/css" href="/theme/css/custom.css">
<link href="//fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic"
rel="stylesheet" type="text/css">
<link href="//fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic"
rel="stylesheet" type="text/css">
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#080816">
<!-- Windows Phone -->
<meta name="msapplication-navbutton-color" content="#080816">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!--
███████╗░█████╗░░██████╗████████╗███████╗██████╗░ ███████╗░██████╗░░██████╗░
██╔════╝██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗ ██╔════╝██╔════╝░██╔════╝░
█████╗░░███████║╚█████╗░░░░██║░░░█████╗░░██████╔╝ █████╗░░██║░░██╗░██║░░██╗░
██╔══╝░░██╔══██║░╚═══██╗░░░██║░░░██╔══╝░░██╔══██╗ ██╔══╝░░██║░░╚██╗██║░░╚██╗
███████╗██║░░██║██████╔╝░░░██║░░░███████╗██║░░██║ ███████╗╚██████╔╝╚██████╔╝
╚══════╝╚═╝░░╚═╝╚═════╝░░░░╚═╝░░░╚══════╝╚═╝░░╚═╝ ╚══════╝░╚═════╝░░╚═════╝░
Bingo! Glad you're here. This is how I got into web-development - by reading the source codes of hundreds of websites. I still do. Isn't curiosity a wonderful thing?
Send me a screenshot of this comment on Twitter @OrangeDurito. I'd be happy to connect :)
-->
</head>
<body>
<header role="banner"><hgroup>
<!-- <h1><a href="/">OrangeDurito.blog</a></h1> -->
<h1><a href="/"><span style="color:orange">Orange</span>Durito.blog</a></h1>
<h2>An amalgamation of engineering and artistry</h2>
</hgroup></header>
<nav role="navigation">
<div class="nav-mobile"><a id="nav-toggle" href="#!"><span></span></a></div>
<ul class="subscription" data-subscription="rss">
</ul>
<ul class="main-navigation">
<li><a href="/">Home</a></li>
<li><a href="/pages/about.html">About</a></li>
<li><a href="/pages/contact.html">Contact</a></li>
<li><a href="/pages/portfolio.html">Portfolio</a></li>
<li><a href="/archives.html">Archive</a></li>
<li><a href="http://chandansinha.me" target="_blank">Personal Website</a></li>
</ul> </nav>
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">Making My Own Discord Bots</h1>
<p class="meta">
<time datetime="2022-04-17T23:15:00+05:30" pubdate>Sun 17 April 2022</time> </p>
</header>
<div class="entry-content"><h2>Prologue</h2>
<p>Lately, I have been spending a considerable time on Discord. For one, most of our lab conversations happen on Discord and secondly, I have finally started to realize the power of this platform to create an engaging community. Seriously, Discord is awesome! You have different servers of your interest with different channels within, it has pretty decent photos and videos support and you can have group voice and videos calls. But the important of all, which is cherry on the cake, are the Discord bots. They can extend the functionality of this platform multifold. Any task that is mundane or tedious for human intervention can be delegated to bots -
- [x] moderation
- [x] saying hi
- [x] summarizing information
- [x] server health monitoring
- [x] list of rocket launches
- [x] telling jokes</p>
<p>You get the idea. Now, it is the last two that I focused on for my Weekend Project. </p>
<p>First of all, follow the setup steps mentioned <a href="https://www.digitaltrends.com/gaming/how-to-make-a-discord-bot/">here</a> for a rudimentary Discord bot connection and testing. After that, all you are limited by is your imagination and the availability of a good API. That's it. Here's my <code>bot.js</code> file for the 'Upcoming Launches' bot which returns a list of next 10 rocket launches whenever you type and enter <code>!launch</code> on Discord -</p>
<div class="highlight"><pre><span></span><code><span class="kd">var</span><span class="w"> </span><span class="nx">Discord</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'discord.io'</span><span class="p">);</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">logger</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'winston'</span><span class="p">);</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">auth</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'./auth.json'</span><span class="p">);</span>
<span class="kd">const</span><span class="w"> </span><span class="nx">axios</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'axios'</span><span class="p">)</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">disc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'discord.js'</span><span class="p">)</span>
<span class="c1">// Configure logger settings</span>
<span class="nx">logger</span><span class="p">.</span><span class="nx">remove</span><span class="p">(</span><span class="nx">logger</span><span class="p">.</span><span class="nx">transports</span><span class="p">.</span><span class="nx">Console</span><span class="p">);</span>
<span class="nx">logger</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="ow">new</span><span class="w"> </span><span class="nx">logger</span><span class="p">.</span><span class="nx">transports</span><span class="p">.</span><span class="nx">Console</span><span class="p">,</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">colorize</span><span class="o">:</span><span class="w"> </span><span class="kc">true</span>
<span class="p">});</span>
<span class="nx">logger</span><span class="p">.</span><span class="nx">level</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'debug'</span><span class="p">;</span>
<span class="c1">// Initialize Discord Bot</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">bot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nx">Discord</span><span class="p">.</span><span class="nx">Client</span><span class="p">({</span>
<span class="w"> </span><span class="nx">token</span><span class="o">:</span><span class="w"> </span><span class="nx">auth</span><span class="p">.</span><span class="nx">token</span><span class="p">,</span>
<span class="w"> </span><span class="nx">autorun</span><span class="o">:</span><span class="w"> </span><span class="kc">true</span>
<span class="p">});</span>
<span class="nx">bot</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">'ready'</span><span class="p">,</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="p">(</span><span class="nx">evt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">logger</span><span class="p">.</span><span class="nx">info</span><span class="p">(</span><span class="s1">'Connected'</span><span class="p">);</span>
<span class="w"> </span><span class="nx">logger</span><span class="p">.</span><span class="nx">info</span><span class="p">(</span><span class="s1">'Logged in as: '</span><span class="p">);</span>
<span class="w"> </span><span class="c1">// logger.info(bot.username + ' - (' + bot.id + ')');</span>
<span class="w"> </span><span class="nx">logger</span><span class="p">.</span><span class="nx">info</span><span class="p">(</span><span class="nx">bot</span><span class="p">.</span><span class="nx">username</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">bot</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">'message'</span><span class="p">,</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="p">(</span><span class="nx">user</span><span class="p">,</span><span class="w"> </span><span class="nx">userID</span><span class="p">,</span><span class="w"> </span><span class="nx">channelID</span><span class="p">,</span><span class="w"> </span><span class="nx">message</span><span class="p">,</span><span class="w"> </span><span class="nx">evt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="c1">// Our bot needs to know if it will execute a command</span>
<span class="c1">// It will listen for messages that will start with `!`</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nx">message</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span><span class="w"> </span><span class="mf">1</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s1">'!'</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">message</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mf">1</span><span class="p">).</span><span class="nx">split</span><span class="p">(</span><span class="s1">' '</span><span class="p">);</span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">cmd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">args</span><span class="p">[</span><span class="mf">0</span><span class="p">];</span>
<span class="w"> </span><span class="nx">args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">args</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="mf">1</span><span class="p">);</span>
<span class="w"> </span><span class="k">switch</span><span class="p">(</span><span class="nx">cmd</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="s1">'launch'</span><span class="o">:</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">axiosOptions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">method</span><span class="o">:</span><span class="w"> </span><span class="s2">"get"</span><span class="p">,</span>
<span class="w"> </span><span class="nx">url</span><span class="o">:</span><span class="w"> </span><span class="sb">`https://ll.thespacedevs.com/2.0.0/launch/upcoming/`</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="nx">axios</span><span class="p">(</span><span class="nx">axiosOptions</span><span class="p">)</span>
<span class="w"> </span><span class="p">.</span><span class="nx">then</span><span class="p">(</span><span class="nx">response</span><span class="w"> </span><span class="p">=></span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// console.log(response.data)</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">table</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">response</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">results</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">launchlist</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">""</span><span class="p">;</span>
<span class="w"> </span><span class="nx">table</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">item</span><span class="w"> </span><span class="p">=></span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">net_time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nb">Date</span><span class="p">(</span><span class="nx">item</span><span class="p">.</span><span class="nx">net</span><span class="p">)</span>
<span class="w"> </span><span class="nx">launchlist</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="sb">`- </span><span class="si">${</span><span class="nx">item</span><span class="p">.</span><span class="nx">name</span><span class="si">}</span><span class="sb">, </span><span class="si">${</span><span class="nx">net_time</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">slice</span><span class="p">(</span><span class="o">-</span><span class="mf">100</span><span class="p">,</span><span class="o">-</span><span class="mf">42</span><span class="p">)</span><span class="si">}</span><span class="sb">, </span><span class="si">${</span><span class="nx">net_time</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">slice</span><span class="p">(</span><span class="o">-</span><span class="mf">41</span><span class="p">)</span><span class="si">}</span><span class="sb">\n`</span>
<span class="w"> </span><span class="p">});</span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">embed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nx">disc</span><span class="p">.</span><span class="nx">MessageEmbed</span><span class="p">()</span>
<span class="w"> </span><span class="p">.</span><span class="nx">setTitle</span><span class="p">(</span><span class="s1">'Upcoming Launches'</span><span class="p">)</span>
<span class="w"> </span><span class="p">.</span><span class="nx">setDescription</span><span class="p">(</span><span class="nx">launchlist</span><span class="p">)</span>
<span class="w"> </span><span class="p">.</span><span class="nx">setURL</span><span class="p">(</span><span class="s1">'http://chandansinha.me'</span><span class="p">)</span>
<span class="w"> </span><span class="nx">bot</span><span class="p">.</span><span class="nx">sendMessage</span><span class="p">({</span>
<span class="w"> </span><span class="nx">to</span><span class="o">:</span><span class="w"> </span><span class="nx">channelID</span><span class="p">,</span>
<span class="w"> </span><span class="nx">message</span><span class="o">:</span><span class="w"> </span><span class="sb">`> **</span><span class="si">${</span><span class="nx">embed</span><span class="p">.</span><span class="nx">title</span><span class="si">}</span><span class="sb">** \n</span><span class="si">${</span><span class="nx">embed</span><span class="p">.</span><span class="nx">description</span><span class="si">}</span><span class="sb">`</span>
<span class="w"> </span><span class="p">});</span>
<span class="w"> </span><span class="p">})</span><span class="w"> </span>
<span class="w"> </span><span class="k">break</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">});</span>
</code></pre></div>
<p>I struggled with composing a rich text message with <code>discord.io</code>, so after scratching my head for 3 days and looking through the poor documentation I finally decided to go with <code>discord.js</code> in conjunction with the former. I also used <code>axios</code> library for HTTP request to query the API. </p>
<p>Similarly, here is the code for my joke bot 'Hoot Hoot' which tells you a joke everytime you type and enter <code>!joke</code> on Discord -</p>
<div class="highlight"><pre><span></span><code><span class="kd">var</span><span class="w"> </span><span class="nx">Discord</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'discord.io'</span><span class="p">);</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">logger</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'winston'</span><span class="p">);</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">auth</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'./auth.json'</span><span class="p">);</span>
<span class="kd">const</span><span class="w"> </span><span class="nx">axios</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'axios'</span><span class="p">)</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">disc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">require</span><span class="p">(</span><span class="s1">'discord.js'</span><span class="p">)</span>
<span class="c1">// Configure logger settings</span>
<span class="nx">logger</span><span class="p">.</span><span class="nx">remove</span><span class="p">(</span><span class="nx">logger</span><span class="p">.</span><span class="nx">transports</span><span class="p">.</span><span class="nx">Console</span><span class="p">);</span>
<span class="nx">logger</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="ow">new</span><span class="w"> </span><span class="nx">logger</span><span class="p">.</span><span class="nx">transports</span><span class="p">.</span><span class="nx">Console</span><span class="p">,</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">colorize</span><span class="o">:</span><span class="w"> </span><span class="kc">true</span>
<span class="p">});</span>
<span class="nx">logger</span><span class="p">.</span><span class="nx">level</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'debug'</span><span class="p">;</span>
<span class="c1">// Initialize Discord Bot</span>
<span class="kd">var</span><span class="w"> </span><span class="nx">bot</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nx">Discord</span><span class="p">.</span><span class="nx">Client</span><span class="p">({</span>
<span class="w"> </span><span class="nx">token</span><span class="o">:</span><span class="w"> </span><span class="nx">auth</span><span class="p">.</span><span class="nx">token</span><span class="p">,</span>
<span class="w"> </span><span class="nx">autorun</span><span class="o">:</span><span class="w"> </span><span class="kc">true</span>
<span class="p">});</span>
<span class="nx">bot</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">'ready'</span><span class="p">,</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="p">(</span><span class="nx">evt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">logger</span><span class="p">.</span><span class="nx">info</span><span class="p">(</span><span class="s1">'Connected'</span><span class="p">);</span>
<span class="w"> </span><span class="nx">logger</span><span class="p">.</span><span class="nx">info</span><span class="p">(</span><span class="s1">'Logged in as: '</span><span class="p">);</span>
<span class="w"> </span><span class="c1">// logger.info(bot.username + ' - (' + bot.id + ')');</span>
<span class="w"> </span><span class="nx">logger</span><span class="p">.</span><span class="nx">info</span><span class="p">(</span><span class="nx">bot</span><span class="p">.</span><span class="nx">username</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">bot</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">'message'</span><span class="p">,</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="p">(</span><span class="nx">user</span><span class="p">,</span><span class="w"> </span><span class="nx">userID</span><span class="p">,</span><span class="w"> </span><span class="nx">channelID</span><span class="p">,</span><span class="w"> </span><span class="nx">message</span><span class="p">,</span><span class="w"> </span><span class="nx">evt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="c1">// Our bot needs to know if it will execute a command</span>
<span class="c1">// It will listen for messages that will start with `!`</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nx">message</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span><span class="w"> </span><span class="mf">1</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s1">'!'</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">message</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mf">1</span><span class="p">).</span><span class="nx">split</span><span class="p">(</span><span class="s1">' '</span><span class="p">);</span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">cmd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">args</span><span class="p">[</span><span class="mf">0</span><span class="p">];</span>
<span class="w"> </span><span class="nx">args</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">args</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="mf">1</span><span class="p">);</span>
<span class="w"> </span><span class="k">switch</span><span class="p">(</span><span class="nx">cmd</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="s1">'joke'</span><span class="o">:</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">axiosOptions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">method</span><span class="o">:</span><span class="w"> </span><span class="s2">"get"</span><span class="p">,</span>
<span class="w"> </span><span class="nx">url</span><span class="o">:</span><span class="w"> </span><span class="sb">`https://v2.jokeapi.dev/joke/Any`</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="nx">axios</span><span class="p">(</span><span class="nx">axiosOptions</span><span class="p">)</span>
<span class="w"> </span><span class="p">.</span><span class="nx">then</span><span class="p">(</span><span class="nx">response</span><span class="w"> </span><span class="p">=></span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">response</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">type</span>
<span class="w"> </span><span class="k">if</span><span class="p">(</span><span class="nx">type</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s1">'single'</span><span class="p">){</span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">whole_joke</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">response</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">joke</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="p">(</span><span class="nx">type</span><span class="o">==</span><span class="s1">'twopart'</span><span class="p">){</span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">whole_joke</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sb">`</span><span class="si">${</span><span class="nx">response</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">setup</span><span class="si">}</span><span class="sb"> \n</span><span class="si">${</span><span class="nx">response</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">delivery</span><span class="si">}</span><span class="sb">`</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">embed</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nx">disc</span><span class="p">.</span><span class="nx">MessageEmbed</span><span class="p">()</span>
<span class="w"> </span><span class="p">.</span><span class="nx">setTitle</span><span class="p">(</span><span class="s2">"Hoot Hoot! Here's a joke for yah!"</span><span class="p">)</span>
<span class="w"> </span><span class="p">.</span><span class="nx">setDescription</span><span class="p">(</span><span class="nx">whole_joke</span><span class="p">)</span>
<span class="w"> </span><span class="p">.</span><span class="nx">setURL</span><span class="p">(</span><span class="s1">'http://chandansinha.me'</span><span class="p">)</span>
<span class="w"> </span><span class="nx">bot</span><span class="p">.</span><span class="nx">sendMessage</span><span class="p">({</span>
<span class="w"> </span><span class="nx">to</span><span class="o">:</span><span class="w"> </span><span class="nx">channelID</span><span class="p">,</span>
<span class="w"> </span><span class="nx">message</span><span class="o">:</span><span class="w"> </span><span class="sb">`> **</span><span class="si">${</span><span class="nx">embed</span><span class="p">.</span><span class="nx">title</span><span class="si">}</span><span class="sb">** \n</span><span class="si">${</span><span class="nx">embed</span><span class="p">.</span><span class="nx">description</span><span class="si">}</span><span class="sb">`</span>
<span class="w"> </span><span class="p">});</span>
<span class="w"> </span><span class="p">})</span><span class="w"> </span>
<span class="w"> </span><span class="k">break</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">});</span>
<span class="c1">// https://sv443.net/jokeapi/v2/</span>
</code></pre></div>
<h2>Next Step</h2>
<ul>
<li>https://www.writebots.com/discord-bot-hosting/</li>
</ul></div>
<footer>
<p class="meta">
<span class="byline author vcard">
Posted by <span class="fn">
Chandan Sinha
</span>
</span>
<time datetime="2022-04-17T23:15:00+05:30" pubdate>Sun 17 April 2022</time> <span class="categories">
<a class='category' href='/category/programming.html'>Programming</a>
</span>
<span class="categories">
<a class="category" href="/tag/engineering.html">engineering</a>, <a class="category" href="/tag/javascript.html">javascript</a>, <a class="category" href="/tag/learning.html">learning</a>, <a class="category" href="/tag/software.html">software</a>, <a class="category" href="/tag/troubleshooting.html">troubleshooting</a> </span>
</p><div class="sharing">
</div> </footer>
</article>
<section>
<h1>Comments</h1>
<div id="disqus_thread" aria-live="polite"> <script type="text/javascript">
var disqus_shortname = 'mechanicalcodertechblog';
// // var disqus_identifier = '/making-my-own-discord-bots.html';
// var disqus_url = '/making-my-own-discord-bots.html';
// var disqus_title = 'Making My Own Discord Bots';
//
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = "//" + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
</div>
</section>
<!-- -->
</div>
<aside class="sidebar">
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/techrantsrandom.html">Techrants.Random</a>
</li>
<li class="post">
<a href="/cummins-internship-experience.html">Cummins Internship Experience</a>
</li>
<li class="post">
<a href="/spacevt-experience.html">Space@VT Experience</a>
</li>
<li class="post">
<a href="/acsl-research-work.html">ACSL Research Work</a>
</li>
<li class="post">
<a href="/making-my-own-discord-bots.html">Making My Own Discord Bots</a>
</li>
</ul>
</section>
<section>
<h1>Categories</h1>
<ul id="recent_posts">
<li><a href="/category/aerospace.html">Aerospace</a> (3)</li>
<li><a href="/category/design.html">Design</a> (4)</li>
<li><a href="/category/filmmaking.html">Filmmaking</a> (3)</li>
<li><a href="/category/life.html">Life</a> (4)</li>
<li><a href="/category/programming.html">Programming</a> (8)</li>
<li><a href="/category/research.html">Research</a> (4)</li>
<li><a href="/category/technology.html">Technology</a> (7)</li>
</ul>
</section>
<!-- <section>
<h1>Tags</h1>
<a href="/tag/intership.html">intership</a>, <a href="/tag/research.html">research</a>, <a href="/tag/engineering.html">engineering</a>, <a href="/tag/programming.html">programming</a>, <a href="/tag/events.html">events</a>, <a href="/tag/learning.html">learning</a>, <a href="/tag/fun.html">fun</a>, <a href="/tag/life.html">life</a>, <a href="/tag/aerospace.html">aerospace</a>, <a href="/tag/masters.html">masters</a>, <a href="/tag/space.html">space</a>, <a href="/tag/technology.html">technology</a>, <a href="/tag/javascript.html">javascript</a>, <a href="/tag/software.html">software</a>, <a href="/tag/troubleshooting.html">troubleshooting</a>, <a href="/tag/features.html">features</a>, <a href="/tag/notes.html">notes</a>, <a href="/tag/web-development.html">web-development</a>, <a href="/tag/editing.html">editing</a>, <a href="/tag/art.html">art</a>, <a href="/tag/creativity.html">creativity</a>, <a href="/tag/iisc.html">IISc</a>, <a href="/tag/combustion.html">combustion</a>, <a href="/tag/blogging.html">blogging</a>, <a href="/tag/design.html">design</a>, <a href="/tag/test.html">test</a>, <a href="/tag/product-design.html">product-design</a>, <a href="/tag/exploration.html">exploration</a>, <a href="/tag/science.html">science</a>, <a href="/tag/markdown.html">markdown</a>, <a href="/tag/pelican.html">pelican</a>, <a href="/tag/automation.html">automation</a>, <a href="/tag/letter.html">letter</a>, <a href="/tag/advice.html">advice</a>, <a href="/tag/mathematics.html">mathematics</a>, <a href="/tag/feature.html">feature</a>, <a href="/tag/internship.html">internship</a> </section> -->
<section>
<h1>Internet Coordinates</h1>
<ul>
<li><a href="https://github.com/mechandansinha" target="_blank"><i class="fab fa-github"></i>GitHub</a></li>
<li><a href="https://www.goodreads.com/user/show/37670581-chandan-sinha" target="_blank"><i class="fab fa-goodreads"></i>Goodreads</a></li>
<li><a href="https://in.linkedin.com/in/chandansinha1" target="_blank"><i class="fab fa-linkedin"></i>LinkedIn</a></li>
<li><a href="https://space.stackexchange.com/users/28487/orangedurito" target="_blank"><i class="fab fa-stack-exchange"></i>Stack Exchange</a></li>
<li><a href="https://twitter.com/OrangeDurito" target="_blank"><i class="fab fa-twitter"></i>Twitter</a></li>
<li><a href="https://thevindicatedaxiom.wordpress.com/" target="_blank"><i class="fab fa-wordpress"></i>WordPress</a></li>
<li><a href="https://www.youtube.com/channel/UC-9V3F-jbe9Kq4sN_NJYakw" target="_blank"><i class="fab fa-youtube"></i>YouTube</a></li>
</ul>
</section>
<section>
<h1> Misc. Websites </h1>
<ul>
<li><a href="https://mechanicalcoder.github.io/launch" target="_blank"><i class="fas fa-rocket"></i>Upcoming Rocket Launches</a></li>
<li><a href="https://movie-reviews-reactjs.vercel.app/" target="_blank"><i class="fas fa-film"></i>Movie Reviews</a></li>
<li><a href="https://nextjs-blog-green-pi.vercel.app/" target="_blank"><i class="fas fa-link"></i>NextJS Sample Blog</a></li>
</ul>
</section>
</aside> </div>
</div>
<footer role="contentinfo"><p>
<!-- -->
Copyright © Chandan Sinha 2016–2023 —
<span class="credit">Powered by <a href="http://getpelican.com" target="_blank">Pelican</a> | </span>
<span class= credit"> <a href="https://github.com/duilio/pelican-octopress-theme" target="_blank">Octopress</a> Theme </span>
</p></footer>
<script src="/theme/js/modernizr-2.0.js"></script>
<script src="/theme/js/ender.js"></script>
<script src="/theme/js/octopress.js" type="text/javascript"></script>
<!-- <script type="text/javascript">
var disqus_shortname = 'mechanicalcodertechblog';
// // var disqus_identifier = '/making-my-own-discord-bots.html';
// var disqus_url = '/making-my-own-discord-bots.html';
// var disqus_title = 'Making My Own Discord Bots';
//
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = "//" + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
(function($) {
$(function() {
// Toggle open and close nav styles on click
$('#nav-toggle').click(function() {
$('nav ul').slideToggle();
});
// Hamburger to X toggle
$('#nav-toggle').on('click', function() {
this.classList.toggle('active');
});
});
})(jQuery);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-EHEWDJ9MNH"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-EHEWDJ9MNH');
</script>
</body>
</html>