-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrating_to_async.html
449 lines (435 loc) · 32.7 KB
/
migrating_to_async.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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>v0.10.0으로 이동</title>
<!-- end extra head -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="_static/style.css" type="text/css" />
<link rel="stylesheet" href="_static/codeblocks.css" type="text/css" />
<link rel="stylesheet" href="_static/icons.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<script src="_static/custom.js"></script>
<script src="_static/settings.js"></script>
<script src="_static/copy.js"></script>
<script src="_static/sidebar.js"></script>
<script src="_static/translations.js"></script>
<link rel="shortcut icon" href="_static/discord_py_logo.ico"/>
<link rel="index" title="색인" href="genindex.html" />
<link rel="search" title="검색" href="search.html" />
</head>
<body>
<div class="main-grid">
<header class="grid-item">
<nav>
<a href="index.html" class="main-heading">discord.py</a>
<a href="https://github.com/Rapptz/discord.py" title="GitHub"><span class="material-icons custom-icons">github</span></a>
<a href="https://discord.gg/YbfbxpX" title="Discord"><span class="material-icons custom-icons">discord</span></a>
<a href="faq.html" title="FAQ"><span class="material-icons">help_center</span></a>
<a onclick="mobileSearch.open();" title="검색" id="open-search" class="mobile-only"><span class="material-icons">search</span></a>
<a onclick="mobileSearch.close();" title="Close" id="close-search" class="mobile-only" hidden><span class="material-icons">close</span></a>
</nav>
<nav class="mobile-only">
<form role="search" class="search" action="search.html" method="get">
<div class="search-wrapper">
<input type="search" name="q" placeholder="Search documentation" />
<button type="submit">
<span class="material-icons">search</span>
</button>
</div>
</form>
</nav>
</header>
<div class="sub-header grid-item">
<label for="documentation_select">View Documentation For</label>
<select id="documentation_select" onchange="window.location = this.value;">
<option value="#" selected>discord</option>
<option value="ext/commands/index.html" >discord.ext.commands</option>
<option value="ext/tasks/index.html" >discord.ext.tasks</option>
</select>
<form role="search" class="search" action="search.html" method="get">
<div class="search-wrapper">
<input type="search" name="q" placeholder="Search documentation" />
<button type="submit">
<span class="material-icons">search</span>
</button>
</div>
</form>
<a accesskey="S" class="settings" onclick="settingsModal.open();"><span class="material-icons">settings</span></a>
</div>
<aside class="grid-item">
<span id="hamburger-toggle">
<span class="material-icons">menu</span>
</span>
<span id="settings-toggle" class="settings" onclick="settingsModal.open();">
<span class="material-icons">settings</span>
</span>
<div id="sidebar">
<h3><a href="index.html">목차</a></h3>
<ul>
<li><a class="reference internal" href="#">v0.10.0으로 이동</a><ul>
<li><a class="reference internal" href="#event-registration">이벤트 등록</a></li>
<li><a class="reference internal" href="#event-changes">이벤트 변화들</a></li>
<li><a class="reference internal" href="#coroutines">Coroutines</a></li>
<li><a class="reference internal" href="#iterables">Iterables</a></li>
<li><a class="reference internal" href="#enumerations">Enumerations</a></li>
<li><a class="reference internal" href="#properties">Properties</a></li>
<li><a class="reference internal" href="#member-management">Member Management</a></li>
<li><a class="reference internal" href="#renamed-functions">Renamed Functions</a></li>
<li><a class="reference internal" href="#forced-keyword-arguments">Forced Keyword Arguments</a></li>
<li><a class="reference internal" href="#running-the-client">Running the Client</a></li>
</ul>
</li>
</ul>
</div>
</aside>
<main class="grid-item" role="main">
<section id="migrating-to-v0-10-0">
<span id="migrating-to-async"></span><h1>v0.10.0으로 이동<a class="headerlink" href="#migrating-to-v0-10-0" title="제목 주소">¶</a></h1>
<p>v0.10.0은 라이브러리가 작동하는 방식의 변화 때문에, 라이브러리에 가장 큰 변화가 이루어진 버전입니다.</p>
<p>가장 큰 변화는 라이브러리가 Python 3.4.2 버전 밑의 버전들을 지원하지 않는다는것 입니다. 이것은 <code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio`를</span> <span class="pre">지원하기</span> <span class="pre">위함인데,</span> <span class="pre">더</span> <span class="pre">자세하게</span> <span class="pre">말하면,</span> <span class="pre">:issue:`통신,</span> <span class="pre">응답</span> <span class="pre">관련</span> <span class="pre">문제</span></code> 때문입니다. 다시 말하자면, 결론적으로, ** Python 2.7과 3.3은 더이상 지원을 하지 않는다는 것 입니다.</p>
<p>아래에 있는 내용은 v0.9.0에서 v0.10.0 사이에 일어난 큰 변화들 입니다.</p>
<section id="event-registration">
<h2>이벤트 등록<a class="headerlink" href="#event-registration" title="제목 주소">¶</a></h2>
<p>이벤트들은 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Client.event`로</span> <span class="pre">먼저</span> <span class="pre">등록이</span> <span class="pre">됩니다.</span> <span class="pre">그</span> <span class="pre">사이에</span> <span class="pre">이것은</span> <span class="pre">여전히</span> <span class="pre">가능합니다</span> <span class="pre">:</span> <span class="pre">이벤트들은</span> <span class="pre">``@asyncio.coroutine`()</span></code> 으로 데코레이팅 되야 합니다.</p>
<p>이전:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nd">@client</span><span class="o">.</span><span class="n">event</span>
<span class="k">def</span> <span class="nf">on_message</span><span class="p">(</span><span class="n">message</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>이후:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nd">@client</span><span class="o">.</span><span class="n">event</span>
<span class="nd">@asyncio</span><span class="o">.</span><span class="n">coroutine</span>
<span class="k">def</span> <span class="nf">on_message</span><span class="p">(</span><span class="n">message</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>또는 Python 3.5+ 에서:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nd">@client</span><span class="o">.</span><span class="n">event</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_message</span><span class="p">(</span><span class="n">message</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>타이핑 해야할 것이 많이 때문에, 유틸리티 데코레이터인(<code class="xref py py-meth docutils literal notranslate"><span class="pre">Client.async_event()</span></code>)가 편하게 등록을 하기 위해서 제공됩니다.예시 :</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nd">@client</span><span class="o">.</span><span class="n">async_event</span>
<span class="k">def</span> <span class="nf">on_message</span><span class="p">(</span><span class="n">message</span><span class="p">):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>하지만 조심하세요, 그것은 아직도 코루틴이고, 당신의 다른 코루틴 함수들은 반드시 <code class="docutils literal notranslate"><span class="pre">@asyncio.coroutine``로</span> <span class="pre">데코레이팅</span> <span class="pre">되거나</span> <span class="pre">``async</span> <span class="pre">def</span></code> 형식이여야 합니다.</p>
</section>
<section id="event-changes">
<h2>이벤트 변화들<a class="headerlink" href="#event-changes" title="제목 주소">¶</a></h2>
<p>Some events in v0.9.0 were considered pretty useless due to having no separate states. The main
events that were changed were the <code class="docutils literal notranslate"><span class="pre">_update</span></code> events since previously they had no context on what
was changed.</p>
<p>이전:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">on_channel_update</span><span class="p">(</span><span class="n">channel</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_member_update</span><span class="p">(</span><span class="n">member</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_status</span><span class="p">(</span><span class="n">member</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_server_role_update</span><span class="p">(</span><span class="n">role</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_voice_state_update</span><span class="p">(</span><span class="n">member</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_socket_raw_send</span><span class="p">(</span><span class="n">payload</span><span class="p">,</span> <span class="n">is_binary</span><span class="p">):</span> <span class="k">pass</span>
</pre></div>
</div>
<p>이후:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">on_channel_update</span><span class="p">(</span><span class="n">before</span><span class="p">,</span> <span class="n">after</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_member_update</span><span class="p">(</span><span class="n">before</span><span class="p">,</span> <span class="n">after</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_server_role_update</span><span class="p">(</span><span class="n">before</span><span class="p">,</span> <span class="n">after</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_voice_state_update</span><span class="p">(</span><span class="n">before</span><span class="p">,</span> <span class="n">after</span><span class="p">):</span> <span class="k">pass</span>
<span class="k">def</span> <span class="nf">on_socket_raw_send</span><span class="p">(</span><span class="n">payload</span><span class="p">):</span> <span class="k">pass</span>
</pre></div>
</div>
<p>Note that <code class="docutils literal notranslate"><span class="pre">on_status</span></code> was removed. If you want its functionality, use <a class="reference internal" href="api.html#discord.on_member_update" title="discord.on_member_update"><code class="xref py py-func docutils literal notranslate"><span class="pre">on_member_update()</span></code></a>.
See <a class="reference internal" href="api.html#discord-api-events"><span class="std std-ref">Event Reference</span></a> for more information. Other removed events include <code class="docutils literal notranslate"><span class="pre">on_socket_closed</span></code>, <code class="docutils literal notranslate"><span class="pre">on_socket_receive</span></code>, and <code class="docutils literal notranslate"><span class="pre">on_socket_opened</span></code>.</p>
</section>
<section id="coroutines">
<h2>Coroutines<a class="headerlink" href="#coroutines" title="제목 주소">¶</a></h2>
<p>The biggest change that the library went through is that almost every function in <a class="reference internal" href="api.html#discord.Client" title="discord.Client"><code class="xref py py-class docutils literal notranslate"><span class="pre">Client</span></code></a>
was changed to be a <a class="reference external" href="py:library/asyncio-task.html">coroutine</a>. Functions
that are marked as a coroutine in the documentation must be awaited from or yielded from in order
for the computation to be done. For example…</p>
<p>이전:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">client</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">channel</span><span class="p">,</span> <span class="s1">'Hello'</span><span class="p">)</span>
</pre></div>
</div>
<p>이후:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">yield from</span> <span class="n">client</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">channel</span><span class="p">,</span> <span class="s1">'Hello'</span><span class="p">)</span>
<span class="c1"># or in python 3.5+</span>
<span class="k">await</span> <span class="n">client</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">channel</span><span class="p">,</span> <span class="s1">'Hello'</span><span class="p">)</span>
</pre></div>
</div>
<p>In order for you to <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> or <code class="docutils literal notranslate"><span class="pre">await</span></code> a coroutine then your function must be decorated
with <code class="docutils literal notranslate"><span class="pre">@asyncio.coroutine</span></code> or <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code>.</p>
</section>
<section id="iterables">
<h2>Iterables<a class="headerlink" href="#iterables" title="제목 주소">¶</a></h2>
<p>For performance reasons, many of the internal data structures were changed into a dictionary to support faster
lookup. As a consequence, this meant that some lists that were exposed via the API have changed into iterables
and not sequences. In short, this means that certain attributes now only support iteration and not any of the
sequence functions.</p>
<p>The affected attributes are as follows:</p>
<ul class="simple">
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Client.servers</span></code></p></li>
<li><p><a class="reference internal" href="api.html#discord.Client.private_channels" title="discord.Client.private_channels"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Client.private_channels</span></code></a></p></li>
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Server.channels</span></code></p></li>
<li><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Server.members</span></code></p></li>
</ul>
<p>Some examples of previously valid behaviour that is now invalid</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">client</span><span class="o">.</span><span class="n">servers</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s2">"test"</span><span class="p">:</span>
<span class="c1"># do something</span>
</pre></div>
</div>
<p>Since they are no longer <a class="reference external" href="https://docs.python.org/ko/3/library/stdtypes.html#list" title="(in Python v3.9)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">list</span></code></a>s, they no longer support indexing or any operation other than iterating.
In order to get the old behaviour you should explicitly cast it to a list.</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">servers</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">servers</span><span class="p">)</span>
<span class="c1"># work with servers</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="admonition-title">경고</p>
<p>Due to internal changes of the structure, the order you receive the data in
is not in a guaranteed order.</p>
</div>
</section>
<section id="enumerations">
<h2>Enumerations<a class="headerlink" href="#enumerations" title="제목 주소">¶</a></h2>
<p>Due to dropping support for versions lower than Python 3.4.2, the library can now use
<a class="reference external" href="https://docs.python.org/ko/3/library/enum.html" title="(in Python v3.9)"><span>enum — 열거형 지원</span></a> in places where it makes sense.</p>
<p>The common places where this was changed was in the server region, member status, and channel type.</p>
<p>이전:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">server</span><span class="o">.</span><span class="n">region</span> <span class="o">==</span> <span class="s1">'us-west'</span>
<span class="n">member</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="s1">'online'</span>
<span class="n">channel</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">'text'</span>
</pre></div>
</div>
<p>이후:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">server</span><span class="o">.</span><span class="n">region</span> <span class="o">==</span> <span class="n">discord</span><span class="o">.</span><span class="n">ServerRegion</span><span class="o">.</span><span class="n">us_west</span>
<span class="n">member</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">discord</span><span class="o">.</span><span class="n">Status</span><span class="o">.</span><span class="n">online</span>
<span class="n">channel</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">discord</span><span class="o">.</span><span class="n">ChannelType</span><span class="o">.</span><span class="n">text</span>
</pre></div>
</div>
<p>The main reason for this change was to reduce the use of finicky strings in the API as this
could give users a false sense of power. More information can be found in the <a class="reference internal" href="api.html#discord-api-enums"><span class="std std-ref">Enumerations</span></a> page.</p>
</section>
<section id="properties">
<h2>Properties<a class="headerlink" href="#properties" title="제목 주소">¶</a></h2>
<p>A lot of function calls that returned constant values were changed into Python properties for ease of use
in format strings.</p>
<p>The following functions were changed into properties:</p>
<div class="table-wrapper"><table class="docutils align-default">
<colgroup>
<col style="width: 51%" />
<col style="width: 49%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p>Before</p></td>
<td><p>After</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">User.avatar_url()</span></code></p></td>
<td><p><a class="reference internal" href="api.html#discord.User.avatar_url" title="discord.User.avatar_url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">User.avatar_url</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">User.mention()</span></code></p></td>
<td><p><a class="reference internal" href="api.html#discord.User.mention" title="discord.User.mention"><code class="xref py py-attr docutils literal notranslate"><span class="pre">User.mention</span></code></a></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">Channel.mention()</span></code></p></td>
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Channel.mention</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">Channel.is_default_channel()</span></code></p></td>
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Channel.is_default</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">Role.is_everyone()</span></code></p></td>
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Role.is_everyone</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">Server.get_default_role()</span></code></p></td>
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Server.default_role</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">Server.icon_url()</span></code></p></td>
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Server.icon_url</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">Server.get_default_channel()</span></code></p></td>
<td><p><code class="xref py py-attr docutils literal notranslate"><span class="pre">Server.default_channel</span></code></p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">Message.get_raw_mentions()</span></code></p></td>
<td><p><a class="reference internal" href="api.html#discord.Message.raw_mentions" title="discord.Message.raw_mentions"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Message.raw_mentions</span></code></a></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">Message.get_raw_channel_mentions()</span></code></p></td>
<td><p><a class="reference internal" href="api.html#discord.Message.raw_channel_mentions" title="discord.Message.raw_channel_mentions"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Message.raw_channel_mentions</span></code></a></p></td>
</tr>
</tbody>
</table>
</div></section>
<section id="member-management">
<h2>Member Management<a class="headerlink" href="#member-management" title="제목 주소">¶</a></h2>
<p>Functions that involved banning and kicking were changed.</p>
<div class="table-wrapper"><table class="docutils align-default">
<colgroup>
<col style="width: 55%" />
<col style="width: 45%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p>Before</p></td>
<td><p>After</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">Client.ban(server,</span> <span class="pre">user)</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">Client.ban(member)</span></code></p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">Client.kick(server,</span> <span class="pre">user)</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">Client.kick(member)</span></code></p></td>
</tr>
</tbody>
</table>
</div></section>
<section id="renamed-functions">
<h2>Renamed Functions<a class="headerlink" href="#renamed-functions" title="제목 주소">¶</a></h2>
<p>Functions have been renamed.</p>
<div class="table-wrapper"><table class="docutils align-default">
<colgroup>
<col style="width: 46%" />
<col style="width: 54%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p>Before</p></td>
<td><p>After</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">Client.set_channel_permissions</span></code></p></td>
<td><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">Client.edit_channel_permissions()</span></code></p></td>
</tr>
</tbody>
</table>
</div><p>All the <a class="reference internal" href="api.html#discord.Permissions" title="discord.Permissions"><code class="xref py py-class docutils literal notranslate"><span class="pre">Permissions</span></code></a> related attributes have been renamed and the <cite>can_</cite> prefix has been
dropped. So for example, <code class="docutils literal notranslate"><span class="pre">can_manage_messages</span></code> has become <code class="docutils literal notranslate"><span class="pre">manage_messages</span></code>.</p>
</section>
<section id="forced-keyword-arguments">
<h2>Forced Keyword Arguments<a class="headerlink" href="#forced-keyword-arguments" title="제목 주소">¶</a></h2>
<p>Since 3.0+ of Python, we can now force questions to take in forced keyword arguments. A keyword argument is when you
explicitly specify the name of the variable and assign to it, for example: <code class="docutils literal notranslate"><span class="pre">foo(name='test')</span></code>. Due to this support,
some functions in the library were changed to force things to take said keyword arguments. This is to reduce errors of
knowing the argument order and the issues that could arise from them.</p>
<p>The following parameters are now exclusively keyword arguments:</p>
<ul class="simple">
<li><dl class="simple">
<dt><code class="xref py py-meth docutils literal notranslate"><span class="pre">Client.send_message()</span></code></dt><dd><ul>
<li><p><code class="docutils literal notranslate"><span class="pre">tts</span></code></p></li>
</ul>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt><code class="xref py py-meth docutils literal notranslate"><span class="pre">Client.logs_from()</span></code></dt><dd><ul>
<li><p><code class="docutils literal notranslate"><span class="pre">before</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">after</span></code></p></li>
</ul>
</dd>
</dl>
</li>
<li><dl class="simple">
<dt><code class="xref py py-meth docutils literal notranslate"><span class="pre">Client.edit_channel_permissions()</span></code></dt><dd><ul>
<li><p><code class="docutils literal notranslate"><span class="pre">allow</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">deny</span></code></p></li>
</ul>
</dd>
</dl>
</li>
</ul>
<p>In the documentation you can tell if a function parameter is a forced keyword argument if it is after <code class="docutils literal notranslate"><span class="pre">\*,</span></code>
in the function signature.</p>
</section>
<section id="running-the-client">
<span id="migrating-running"></span><h2>Running the Client<a class="headerlink" href="#running-the-client" title="제목 주소">¶</a></h2>
<p>In earlier versions of discord.py, <code class="docutils literal notranslate"><span class="pre">client.run()</span></code> was a blocking call to the main thread
that called it. In v0.10.0 it is still a blocking call but it handles the event loop for you.
However, in order to do that you must pass in your credentials to <a class="reference internal" href="api.html#discord.Client.run" title="discord.Client.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Client.run()</span></code></a>.</p>
<p>Basically, before:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">client</span><span class="o">.</span><span class="n">login</span><span class="p">(</span><span class="s1">'token'</span><span class="p">)</span>
<span class="n">client</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
</pre></div>
</div>
<p>이후:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">client</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s1">'token'</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="admonition-title">경고</p>
<p>Like in the older <code class="docutils literal notranslate"><span class="pre">Client.run</span></code> function, the newer one must be the one of
the last functions to call. This is because the function is <strong>blocking</strong>. Registering
events or doing anything after <a class="reference internal" href="api.html#discord.Client.run" title="discord.Client.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Client.run()</span></code></a> will not execute until the function
returns.</p>
</div>
<p>This is a utility function that abstracts the event loop for you. There’s no need for
the run call to be blocking and out of your control. Indeed, if you want control of the
event loop then doing so is quite straightforward:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">discord</span>
<span class="kn">import</span> <span class="nn">asyncio</span>
<span class="n">client</span> <span class="o">=</span> <span class="n">discord</span><span class="o">.</span><span class="n">Client</span><span class="p">()</span>
<span class="nd">@asyncio</span><span class="o">.</span><span class="n">coroutine</span>
<span class="k">def</span> <span class="nf">main_task</span><span class="p">():</span>
<span class="k">yield from</span> <span class="n">client</span><span class="o">.</span><span class="n">login</span><span class="p">(</span><span class="s1">'token'</span><span class="p">)</span>
<span class="k">yield from</span> <span class="n">client</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">main_task</span><span class="p">())</span>
<span class="k">except</span><span class="p">:</span>
<span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">logout</span><span class="p">())</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</section>
</section>
</main>
<footer class="grid-item">
© Copyright 2015-2020, Rapptz.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</footer>
</div>
<div id="settings" class="modal" onclick="if (event.target == this){ settingsModal.close(); }" hidden>
<div class="modal-content">
<span class="close" onclick="settingsModal.close();" title="Close">
<span class="material-icons">close</span>
</span>
<h1>Settings</h1>
<h2>Font</h2>
<div class="setting">
<h3>Use a serif font:
<label class="toggle"
title="Use a serif font? Your system font will be used, falling back to serif.">
<input type="checkbox" name="useSerifFont" onclick="updateSetting(this);">
<span class="toggle-slider"></span>
</label>
</h3>
</div>
<h2>Theme</h2>
<div class="setting">
<h3>
<label class="toggle" title="Set your theme based on your system preferences">
<input type="radio" name="setTheme" onclick="updateSetting(this);" value="automatic" checked>
</label>
Automatic
</h3>
<h3>
<label class="toggle" title="Set your theme to light theme">
<input type="radio" name="setTheme" onclick="updateSetting(this);" value="light">
</label>
Light
</h3>
<h3>
<label class="toggle" title="Set your theme to dark theme">
<input type="radio" name="setTheme" onclick="updateSetting(this);" value="dark">
</label>
Dark
</h3>
</div>
</div>
</div>
<div id="to-top" onclick="scrollToTop()" hidden>
<span><span class="material-icons">arrow_upward</span> to top</span>
</div>
</body>
</html>