Sort event references by categories
This commit is contained in:
8921
docs/Python/html/ext/commands/api.html
Normal file
8921
docs/Python/html/ext/commands/api.html
Normal file
File diff suppressed because it is too large
Load Diff
282
docs/Python/html/ext/commands/cogs.html
Normal file
282
docs/Python/html/ext/commands/cogs.html
Normal file
@@ -0,0 +1,282 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cogs</title>
|
||||
<!-- end extra head -->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/basic.css" />
|
||||
<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 data-url_root="../../" id="documentation_options" 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/custom.js"></script>
|
||||
<script src="../../_static/settings.js"></script>
|
||||
<script src="../../_static/copy.js"></script>
|
||||
<script src="../../_static/sidebar.js"></script>
|
||||
<link rel="shortcut icon" href="../../_static/discord_py_logo.ico"/>
|
||||
<link rel="index" title="Index" href="../../genindex.html" />
|
||||
<link rel="search" title="Search" href="../../search.html" />
|
||||
<link rel="next" title="Extensions" href="extensions.html" />
|
||||
<link rel="prev" title="Commands" href="commands.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/TvqYBrGXEm" 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="Search" 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="../../index.html">discord</option>
|
||||
<option value="index.html" selected>discord.ext.commands</option>
|
||||
<option value="../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">Table of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Cogs</a><ul>
|
||||
<li><a class="reference internal" href="#quick-example">Quick Example</a></li>
|
||||
<li><a class="reference internal" href="#cog-registration">Cog Registration</a></li>
|
||||
<li><a class="reference internal" href="#using-cogs">Using Cogs</a></li>
|
||||
<li><a class="reference internal" href="#special-methods">Special Methods</a></li>
|
||||
<li><a class="reference internal" href="#meta-options">Meta Options</a></li>
|
||||
<li><a class="reference internal" href="#inspection">Inspection</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</aside>
|
||||
<main class="grid-item" role="main">
|
||||
|
||||
<section id="cogs">
|
||||
<span id="ext-commands-cogs"></span><h1>Cogs<a class="headerlink" href="#cogs" title="Permalink to this headline">¶</a></h1>
|
||||
<p>There comes a point in your bot’s development when you want to organize a collection of commands, listeners, and some state into one class. Cogs allow you to do just that.</p>
|
||||
<p>The gist:</p>
|
||||
<ul class="simple">
|
||||
<li><p>Each cog is a Python class that subclasses <a class="reference internal" href="api.html#discord.ext.commands.Cog" title="discord.ext.commands.Cog"><code class="xref py py-class docutils literal notranslate"><span class="pre">commands.Cog</span></code></a>.</p></li>
|
||||
<li><p>Every command is marked with the <a class="reference internal" href="api.html#discord.ext.commands.command" title="discord.ext.commands.command"><code class="xref py py-func docutils literal notranslate"><span class="pre">commands.command()</span></code></a> decorator.</p></li>
|
||||
<li><p>Every listener is marked with the <a class="reference internal" href="api.html#discord.ext.commands.Cog.listener" title="discord.ext.commands.Cog.listener"><code class="xref py py-meth docutils literal notranslate"><span class="pre">commands.Cog.listener()</span></code></a> decorator.</p></li>
|
||||
<li><p>Cogs are then registered with the <a class="reference internal" href="api.html#discord.ext.commands.Bot.add_cog" title="discord.ext.commands.Bot.add_cog"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Bot.add_cog()</span></code></a> call.</p></li>
|
||||
<li><p>Cogs are subsequently removed with the <a class="reference internal" href="api.html#discord.ext.commands.Bot.remove_cog" title="discord.ext.commands.Bot.remove_cog"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Bot.remove_cog()</span></code></a> call.</p></li>
|
||||
</ul>
|
||||
<p>It should be noted that cogs are typically used alongside with <a class="reference internal" href="extensions.html#ext-commands-extensions"><span class="std std-ref">Extensions</span></a>.</p>
|
||||
<section id="quick-example">
|
||||
<h2>Quick Example<a class="headerlink" href="#quick-example" title="Permalink to this headline">¶</a></h2>
|
||||
<p>This example cog defines a <code class="docutils literal notranslate"><span class="pre">Greetings</span></code> category for your commands, with a single <a class="reference internal" href="commands.html#ext-commands-commands"><span class="std std-ref">command</span></a> named <code class="docutils literal notranslate"><span class="pre">hello</span></code> as well as a listener to listen to an <a class="reference internal" href="../../api.html#discord-api-events"><span class="std std-ref">Event</span></a>.</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Greetings</span><span class="p">(</span><span class="n">commands</span><span class="o">.</span><span class="n">Cog</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">bot</span> <span class="o">=</span> <span class="n">bot</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">_last_member</span> <span class="o">=</span> <span class="kc">None</span>
|
||||
|
||||
<span class="nd">@commands</span><span class="o">.</span><span class="n">Cog</span><span class="o">.</span><span class="n">listener</span><span class="p">()</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_member_join</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">member</span><span class="p">):</span>
|
||||
<span class="n">channel</span> <span class="o">=</span> <span class="n">member</span><span class="o">.</span><span class="n">guild</span><span class="o">.</span><span class="n">system_channel</span>
|
||||
<span class="k">if</span> <span class="n">channel</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
|
||||
<span class="k">await</span> <span class="n">channel</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="sa">f</span><span class="s1">'Welcome </span><span class="si">{</span><span class="n">member</span><span class="o">.</span><span class="n">mention</span><span class="si">}</span><span class="s1">.'</span><span class="p">)</span>
|
||||
|
||||
<span class="nd">@commands</span><span class="o">.</span><span class="n">command</span><span class="p">()</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ctx</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">member</span><span class="p">:</span> <span class="n">discord</span><span class="o">.</span><span class="n">Member</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
|
||||
<span class="sd">"""Says hello"""</span>
|
||||
<span class="n">member</span> <span class="o">=</span> <span class="n">member</span> <span class="ow">or</span> <span class="n">ctx</span><span class="o">.</span><span class="n">author</span>
|
||||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_last_member</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">_last_member</span><span class="o">.</span><span class="n">id</span> <span class="o">!=</span> <span class="n">member</span><span class="o">.</span><span class="n">id</span><span class="p">:</span>
|
||||
<span class="k">await</span> <span class="n">ctx</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="sa">f</span><span class="s1">'Hello </span><span class="si">{</span><span class="n">member</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s1">~'</span><span class="p">)</span>
|
||||
<span class="k">else</span><span class="p">:</span>
|
||||
<span class="k">await</span> <span class="n">ctx</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="sa">f</span><span class="s1">'Hello </span><span class="si">{</span><span class="n">member</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s1">... This feels familiar.'</span><span class="p">)</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">_last_member</span> <span class="o">=</span> <span class="n">member</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>A couple of technical notes to take into consideration:</p>
|
||||
<ul class="simple">
|
||||
<li><p>All listeners must be explicitly marked via decorator, <a class="reference internal" href="api.html#discord.ext.commands.Cog.listener" title="discord.ext.commands.Cog.listener"><code class="xref py py-meth docutils literal notranslate"><span class="pre">listener()</span></code></a>.</p></li>
|
||||
<li><p>The name of the cog is automatically derived from the class name but can be overridden. See <a class="reference internal" href="#ext-commands-cogs-meta-options"><span class="std std-ref">Meta Options</span></a>.</p></li>
|
||||
<li><p>All commands must now take a <code class="docutils literal notranslate"><span class="pre">self</span></code> parameter to allow usage of instance attributes that can be used to maintain state.</p></li>
|
||||
</ul>
|
||||
</section>
|
||||
<section id="cog-registration">
|
||||
<h2>Cog Registration<a class="headerlink" href="#cog-registration" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Once you have defined your cogs, you need to tell the bot to register the cogs to be used. We do this via the <a class="reference internal" href="api.html#discord.ext.commands.Bot.add_cog" title="discord.ext.commands.Bot.add_cog"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_cog()</span></code></a> method.</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">bot</span><span class="o">.</span><span class="n">add_cog</span><span class="p">(</span><span class="n">Greetings</span><span class="p">(</span><span class="n">bot</span><span class="p">))</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>This binds the cog to the bot, adding all commands and listeners to the bot automatically.</p>
|
||||
<p>Note that we reference the cog by name, which we can override through <a class="reference internal" href="#ext-commands-cogs-meta-options"><span class="std std-ref">Meta Options</span></a>. So if we ever want to remove the cog eventually, we would have to do the following.</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">bot</span><span class="o">.</span><span class="n">remove_cog</span><span class="p">(</span><span class="s1">'Greetings'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="using-cogs">
|
||||
<h2>Using Cogs<a class="headerlink" href="#using-cogs" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Just as we remove a cog by its name, we can also retrieve it by its name as well. This allows us to use a cog as an inter-command communication protocol to share data. For example:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Economy</span><span class="p">(</span><span class="n">commands</span><span class="o">.</span><span class="n">Cog</span><span class="p">):</span>
|
||||
<span class="o">...</span>
|
||||
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">withdraw_money</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">member</span><span class="p">,</span> <span class="n">money</span><span class="p">):</span>
|
||||
<span class="c1"># implementation here</span>
|
||||
<span class="o">...</span>
|
||||
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">deposit_money</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">member</span><span class="p">,</span> <span class="n">money</span><span class="p">):</span>
|
||||
<span class="c1"># implementation here</span>
|
||||
<span class="o">...</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Gambling</span><span class="p">(</span><span class="n">commands</span><span class="o">.</span><span class="n">Cog</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">bot</span> <span class="o">=</span> <span class="n">bot</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">coinflip</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="k">return</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
|
||||
|
||||
<span class="nd">@commands</span><span class="o">.</span><span class="n">command</span><span class="p">()</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">gamble</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ctx</span><span class="p">,</span> <span class="n">money</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
|
||||
<span class="sd">"""Gambles some money."""</span>
|
||||
<span class="hll"> <span class="n">economy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bot</span><span class="o">.</span><span class="n">get_cog</span><span class="p">(</span><span class="s1">'Economy'</span><span class="p">)</span>
|
||||
</span> <span class="k">if</span> <span class="n">economy</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
|
||||
<span class="hll"> <span class="k">await</span> <span class="n">economy</span><span class="o">.</span><span class="n">withdraw_money</span><span class="p">(</span><span class="n">ctx</span><span class="o">.</span><span class="n">author</span><span class="p">,</span> <span class="n">money</span><span class="p">)</span>
|
||||
</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coinflip</span><span class="p">()</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
|
||||
<span class="k">await</span> <span class="n">economy</span><span class="o">.</span><span class="n">deposit_money</span><span class="p">(</span><span class="n">ctx</span><span class="o">.</span><span class="n">author</span><span class="p">,</span> <span class="n">money</span> <span class="o">*</span> <span class="mf">1.5</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="special-methods">
|
||||
<span id="ext-commands-cogs-special-methods"></span><h2>Special Methods<a class="headerlink" href="#special-methods" title="Permalink to this headline">¶</a></h2>
|
||||
<p>As cogs get more complicated and have more commands, there comes a point where we want to customise the behaviour of the entire cog or bot.</p>
|
||||
<p>They are as follows:</p>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference internal" href="api.html#discord.ext.commands.Cog.cog_unload" title="discord.ext.commands.Cog.cog_unload"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.cog_unload()</span></code></a></p></li>
|
||||
<li><p><a class="reference internal" href="api.html#discord.ext.commands.Cog.cog_check" title="discord.ext.commands.Cog.cog_check"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.cog_check()</span></code></a></p></li>
|
||||
<li><p><a class="reference internal" href="api.html#discord.ext.commands.Cog.cog_command_error" title="discord.ext.commands.Cog.cog_command_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.cog_command_error()</span></code></a></p></li>
|
||||
<li><p><a class="reference internal" href="api.html#discord.ext.commands.Cog.cog_before_invoke" title="discord.ext.commands.Cog.cog_before_invoke"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.cog_before_invoke()</span></code></a></p></li>
|
||||
<li><p><a class="reference internal" href="api.html#discord.ext.commands.Cog.cog_after_invoke" title="discord.ext.commands.Cog.cog_after_invoke"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.cog_after_invoke()</span></code></a></p></li>
|
||||
<li><p><a class="reference internal" href="api.html#discord.ext.commands.Cog.bot_check" title="discord.ext.commands.Cog.bot_check"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.bot_check()</span></code></a></p></li>
|
||||
<li><p><a class="reference internal" href="api.html#discord.ext.commands.Cog.bot_check_once" title="discord.ext.commands.Cog.bot_check_once"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.bot_check_once()</span></code></a></p></li>
|
||||
</ul>
|
||||
<p>You can visit the reference to get more detail.</p>
|
||||
</section>
|
||||
<section id="meta-options">
|
||||
<span id="ext-commands-cogs-meta-options"></span><h2>Meta Options<a class="headerlink" href="#meta-options" title="Permalink to this headline">¶</a></h2>
|
||||
<p>At the heart of a cog resides a metaclass, <a class="reference internal" href="api.html#discord.ext.commands.CogMeta" title="discord.ext.commands.CogMeta"><code class="xref py py-class docutils literal notranslate"><span class="pre">commands.CogMeta</span></code></a>, which can take various options to customise some of the behaviour. To do this, we pass keyword arguments to the class definition line. For example, to change the cog name we can pass the <code class="docutils literal notranslate"><span class="pre">name</span></code> keyword argument as follows:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyCog</span><span class="p">(</span><span class="n">commands</span><span class="o">.</span><span class="n">Cog</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'My Cog'</span><span class="p">):</span>
|
||||
<span class="k">pass</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>To see more options that you can set, see the documentation of <a class="reference internal" href="api.html#discord.ext.commands.CogMeta" title="discord.ext.commands.CogMeta"><code class="xref py py-class docutils literal notranslate"><span class="pre">commands.CogMeta</span></code></a>.</p>
|
||||
</section>
|
||||
<section id="inspection">
|
||||
<h2>Inspection<a class="headerlink" href="#inspection" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Since cogs ultimately are classes, we have some tools to help us inspect certain properties of the cog.</p>
|
||||
<p>To get a <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> of commands, we can use <a class="reference internal" href="api.html#discord.ext.commands.Cog.get_commands" title="discord.ext.commands.Cog.get_commands"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.get_commands()</span></code></a>.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">cog</span> <span class="o">=</span> <span class="n">bot</span><span class="o">.</span><span class="n">get_cog</span><span class="p">(</span><span class="s1">'Greetings'</span><span class="p">)</span>
|
||||
<span class="gp">>>> </span><span class="n">commands</span> <span class="o">=</span> <span class="n">cog</span><span class="o">.</span><span class="n">get_commands</span><span class="p">()</span>
|
||||
<span class="gp">>>> </span><span class="nb">print</span><span class="p">([</span><span class="n">c</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">commands</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>If we want to get the subcommands as well, we can use the <a class="reference internal" href="api.html#discord.ext.commands.Cog.walk_commands" title="discord.ext.commands.Cog.walk_commands"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.walk_commands()</span></code></a> generator.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">([</span><span class="n">c</span><span class="o">.</span><span class="n">qualified_name</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">cog</span><span class="o">.</span><span class="n">walk_commands</span><span class="p">()])</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>To do the same with listeners, we can query them with <a class="reference internal" href="api.html#discord.ext.commands.Cog.get_listeners" title="discord.ext.commands.Cog.get_listeners"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Cog.get_listeners()</span></code></a>. This returns a list of tuples – the first element being the listener name and the second one being the actual function itself.</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">func</span> <span class="ow">in</span> <span class="n">cog</span><span class="o">.</span><span class="n">get_listeners</span><span class="p">():</span>
|
||||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="s1">'->'</span><span class="p">,</span> <span class="n">func</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
</main>
|
||||
<footer class="grid-item">
|
||||
© Copyright 2015-present, Rapptz.
|
||||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.2.0.
|
||||
</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>
|
||||
1021
docs/Python/html/ext/commands/commands.html
Normal file
1021
docs/Python/html/ext/commands/commands.html
Normal file
File diff suppressed because it is too large
Load Diff
200
docs/Python/html/ext/commands/extensions.html
Normal file
200
docs/Python/html/ext/commands/extensions.html
Normal file
@@ -0,0 +1,200 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Extensions</title>
|
||||
<!-- end extra head -->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/basic.css" />
|
||||
<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 data-url_root="../../" id="documentation_options" 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/custom.js"></script>
|
||||
<script src="../../_static/settings.js"></script>
|
||||
<script src="../../_static/copy.js"></script>
|
||||
<script src="../../_static/sidebar.js"></script>
|
||||
<link rel="shortcut icon" href="../../_static/discord_py_logo.ico"/>
|
||||
<link rel="index" title="Index" href="../../genindex.html" />
|
||||
<link rel="search" title="Search" href="../../search.html" />
|
||||
<link rel="next" title="Slash Commands" href="slash-commands.html" />
|
||||
<link rel="prev" title="Cogs" href="cogs.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/TvqYBrGXEm" 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="Search" 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="../../index.html">discord</option>
|
||||
<option value="index.html" selected>discord.ext.commands</option>
|
||||
<option value="../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">Table of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#">Extensions</a><ul>
|
||||
<li><a class="reference internal" href="#primer">Primer</a></li>
|
||||
<li><a class="reference internal" href="#reloading">Reloading</a></li>
|
||||
<li><a class="reference internal" href="#cleaning-up">Cleaning Up</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</aside>
|
||||
<main class="grid-item" role="main">
|
||||
|
||||
<section id="extensions">
|
||||
<span id="ext-commands-extensions"></span><h1>Extensions<a class="headerlink" href="#extensions" title="Permalink to this headline">¶</a></h1>
|
||||
<p>There comes a time in the bot development when you want to extend the bot functionality at run-time and quickly unload and reload code (also called hot-reloading). The command framework comes with this ability built-in, with a concept called <strong>extensions</strong>.</p>
|
||||
<section id="primer">
|
||||
<h2>Primer<a class="headerlink" href="#primer" title="Permalink to this headline">¶</a></h2>
|
||||
<p>An extension at its core is a python file with an entry point called <code class="docutils literal notranslate"><span class="pre">setup</span></code>. This setup must be a plain Python function (not a coroutine). It takes a single parameter – the <a class="reference internal" href="api.html#discord.ext.commands.Bot" title="discord.ext.commands.Bot"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bot</span></code></a> that loads the extension.</p>
|
||||
<p>An example extension looks like this:</p>
|
||||
<div class="literal-block-wrapper docutils container" id="id1">
|
||||
<div class="code-block-caption"><span class="caption-text">hello.py</span><a class="headerlink" href="#id1" title="Permalink to this code">¶</a></div>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">discord.ext</span> <span class="kn">import</span> <span class="n">commands</span>
|
||||
|
||||
<span class="nd">@commands</span><span class="o">.</span><span class="n">command</span><span class="p">()</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">ctx</span><span class="p">):</span>
|
||||
<span class="k">await</span> <span class="n">ctx</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="sa">f</span><span class="s1">'Hello </span><span class="si">{</span><span class="n">ctx</span><span class="o">.</span><span class="n">author</span><span class="o">.</span><span class="n">display_name</span><span class="si">}</span><span class="s1">.'</span><span class="p">)</span>
|
||||
|
||||
<span class="hll"><span class="k">def</span> <span class="nf">setup</span><span class="p">(</span><span class="n">bot</span><span class="p">):</span>
|
||||
</span><span class="hll"> <span class="n">bot</span><span class="o">.</span><span class="n">add_command</span><span class="p">(</span><span class="n">hello</span><span class="p">)</span>
|
||||
</span></pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<p>In this example we define a simple command, and when the extension is loaded this command is added to the bot. Now the final step to this is loading the extension, which we do by calling <a class="reference internal" href="api.html#discord.ext.commands.Bot.load_extension" title="discord.ext.commands.Bot.load_extension"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Bot.load_extension()</span></code></a>. To load this extension we call <code class="docutils literal notranslate"><span class="pre">bot.load_extension('hello')</span></code>.</p>
|
||||
<div class="helpful admonition">
|
||||
<p class="admonition-title">Cogs</p>
|
||||
<p>Extensions are usually used in conjunction with cogs. To read more about them, check out the documentation, <a class="reference internal" href="cogs.html#ext-commands-cogs"><span class="std std-ref">Cogs</span></a>.</p>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>Extension paths are ultimately similar to the import mechanism. What this means is that if there is a folder, then it must be dot-qualified. For example to load an extension in <code class="docutils literal notranslate"><span class="pre">plugins/hello.py</span></code> then we use the string <code class="docutils literal notranslate"><span class="pre">plugins.hello</span></code>.</p>
|
||||
</div>
|
||||
</section>
|
||||
<section id="reloading">
|
||||
<h2>Reloading<a class="headerlink" href="#reloading" title="Permalink to this headline">¶</a></h2>
|
||||
<p>When you make a change to the extension and want to reload the references, the library comes with a function to do this for you, <a class="reference internal" href="api.html#discord.ext.commands.Bot.reload_extension" title="discord.ext.commands.Bot.reload_extension"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Bot.reload_extension()</span></code></a>.</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">bot</span><span class="o">.</span><span class="n">reload_extension</span><span class="p">(</span><span class="s1">'hello'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Once the extension reloads, any changes that we did will be applied. This is useful if we want to add or remove functionality without restarting our bot. If an error occurred during the reloading process, the bot will pretend as if the reload never happened.</p>
|
||||
</section>
|
||||
<section id="cleaning-up">
|
||||
<h2>Cleaning Up<a class="headerlink" href="#cleaning-up" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Although rare, sometimes an extension needs to clean-up or know when it’s being unloaded. For cases like these, there is another entry point named <code class="docutils literal notranslate"><span class="pre">teardown</span></code> which is similar to <code class="docutils literal notranslate"><span class="pre">setup</span></code> except called when the extension is unloaded.</p>
|
||||
<div class="literal-block-wrapper docutils container" id="id2">
|
||||
<div class="code-block-caption"><span class="caption-text">basic_ext.py</span><a class="headerlink" href="#id2" title="Permalink to this code">¶</a></div>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">setup</span><span class="p">(</span><span class="n">bot</span><span class="p">):</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s1">'I am being loaded!'</span><span class="p">)</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">teardown</span><span class="p">(</span><span class="n">bot</span><span class="p">):</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s1">'I am being unloaded!'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
</main>
|
||||
<footer class="grid-item">
|
||||
© Copyright 2015-present, Rapptz.
|
||||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.2.0.
|
||||
</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>
|
||||
184
docs/Python/html/ext/commands/index.html
Normal file
184
docs/Python/html/ext/commands/index.html
Normal file
@@ -0,0 +1,184 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>discord.ext.commands – Bot commands framework</title>
|
||||
<!-- end extra head -->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/basic.css" />
|
||||
<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 data-url_root="../../" id="documentation_options" 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/custom.js"></script>
|
||||
<script src="../../_static/settings.js"></script>
|
||||
<script src="../../_static/copy.js"></script>
|
||||
<script src="../../_static/sidebar.js"></script>
|
||||
<link rel="shortcut icon" href="../../_static/discord_py_logo.ico"/>
|
||||
<link rel="index" title="Index" href="../../genindex.html" />
|
||||
<link rel="search" title="Search" href="../../search.html" />
|
||||
<link rel="next" title="Commands" href="commands.html" />
|
||||
<link rel="prev" title="Welcome to discord.py" href="../../index.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/TvqYBrGXEm" 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="Search" 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="../../index.html">discord</option>
|
||||
<option value="#" selected>discord.ext.commands</option>
|
||||
<option value="../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="settings-toggle" class="settings" onclick="settingsModal.open();">
|
||||
<span class="material-icons">settings</span>
|
||||
</span>
|
||||
<div id="sidebar">
|
||||
</div>
|
||||
</aside>
|
||||
<main class="grid-item" role="main">
|
||||
|
||||
<section id="discord-ext-commands-bot-commands-framework">
|
||||
<span id="discord-ext-commands"></span><h1><code class="docutils literal notranslate"><span class="pre">discord.ext.commands</span></code> – Bot commands framework<a class="headerlink" href="#discord-ext-commands-bot-commands-framework" title="Permalink to this headline">¶</a></h1>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">discord.py</span></code> offers a lower level aspect on interacting with Discord. Often times, the library is used for the creation of
|
||||
bots. However this task can be daunting and confusing to get correctly the first time. Many times there comes a repetition in
|
||||
creating a bot command framework that is extensible, flexible, and powerful. For this reason, <code class="docutils literal notranslate"><span class="pre">discord.py</span></code> comes with an
|
||||
extension library that handles this for you.</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="commands.html">Commands</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="commands.html#parameters">Parameters</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="commands.html#invocation-context">Invocation Context</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="commands.html#converters">Converters</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="commands.html#error-handling">Error Handling</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="commands.html#checks">Checks</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="cogs.html">Cogs</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="cogs.html#quick-example">Quick Example</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="cogs.html#cog-registration">Cog Registration</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="cogs.html#using-cogs">Using Cogs</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="cogs.html#special-methods">Special Methods</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="cogs.html#meta-options">Meta Options</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="cogs.html#inspection">Inspection</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="extensions.html">Extensions</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="extensions.html#primer">Primer</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="extensions.html#reloading">Reloading</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="extensions.html#cleaning-up">Cleaning Up</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="slash-commands.html">Slash Commands</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#bots">Bots</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#prefix-helpers">Prefix Helpers</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#event-reference">Event Reference</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#commands">Commands</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#cogs">Cogs</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#help-commands">Help Commands</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#enums">Enums</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#checks">Checks</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#cooldown">Cooldown</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#context">Context</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#converters">Converters</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#exceptions">Exceptions</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
</main>
|
||||
<footer class="grid-item">
|
||||
© Copyright 2015-present, Rapptz.
|
||||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.2.0.
|
||||
</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>
|
||||
149
docs/Python/html/ext/commands/slash-commands.html
Normal file
149
docs/Python/html/ext/commands/slash-commands.html
Normal file
@@ -0,0 +1,149 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Slash Commands</title>
|
||||
<!-- end extra head -->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/basic.css" />
|
||||
<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 data-url_root="../../" id="documentation_options" 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/custom.js"></script>
|
||||
<script src="../../_static/settings.js"></script>
|
||||
<script src="../../_static/copy.js"></script>
|
||||
<script src="../../_static/sidebar.js"></script>
|
||||
<link rel="shortcut icon" href="../../_static/discord_py_logo.ico"/>
|
||||
<link rel="index" title="Index" href="../../genindex.html" />
|
||||
<link rel="search" title="Search" href="../../search.html" />
|
||||
<link rel="next" title="API Reference" href="api.html" />
|
||||
<link rel="prev" title="Extensions" href="extensions.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/TvqYBrGXEm" 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="Search" 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="../../index.html">discord</option>
|
||||
<option value="index.html" selected>discord.ext.commands</option>
|
||||
<option value="../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="settings-toggle" class="settings" onclick="settingsModal.open();">
|
||||
<span class="material-icons">settings</span>
|
||||
</span>
|
||||
<div id="sidebar">
|
||||
</div>
|
||||
</aside>
|
||||
<main class="grid-item" role="main">
|
||||
|
||||
<section id="slash-commands">
|
||||
<span id="ext-commands-slash-commands"></span><h1>Slash Commands<a class="headerlink" href="#slash-commands" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Slash Commands are currently supported in enhanced-discord.py using a system on top of ext.commands.</p>
|
||||
<p>This system is very simple to use, and can be enabled via <a class="reference internal" href="api.html#discord.ext.commands.Bot.slash_commands" title="discord.ext.commands.Bot.slash_commands"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Bot.slash_commands</span></code></a> globally,
|
||||
or only for specific commands via <a class="reference internal" href="api.html#discord.ext.commands.Command.slash_command" title="discord.ext.commands.Command.slash_command"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Command.slash_command</span></code></a>.</p>
|
||||
<p>There is also the parameter <code class="docutils literal notranslate"><span class="pre">slash_command_guilds</span></code> which can be passed to either <a class="reference internal" href="api.html#discord.ext.commands.Bot" title="discord.ext.commands.Bot"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bot</span></code></a> or the command
|
||||
decorator in order to only upload the commands as guild commands to these specific guild IDs, however this
|
||||
should only be used for testing or small (<10 guilds) bots.</p>
|
||||
<p>If you want to add option descriptions to your commands, you should use <a class="reference internal" href="api.html#discord.ext.commands.Option" title="discord.ext.commands.Option"><code class="xref py py-class docutils literal notranslate"><span class="pre">Option</span></code></a></p>
|
||||
<p>For troubleshooting, see the <a class="reference internal" href="../../faq.html#ext-commands-slash-command-troubleshooting"><span class="std std-ref">FAQ</span></a></p>
|
||||
<div class="admonition-slash-command-only admonition">
|
||||
<p class="admonition-title">Slash Command Only</p>
|
||||
<p>For parts of the docs specific to slash commands, look for this box!</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
</main>
|
||||
<footer class="grid-item">
|
||||
© Copyright 2015-present, Rapptz.
|
||||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.2.0.
|
||||
</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>
|
||||
704
docs/Python/html/ext/tasks/index.html
Normal file
704
docs/Python/html/ext/tasks/index.html
Normal file
@@ -0,0 +1,704 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>discord.ext.tasks – asyncio.Task helpers</title>
|
||||
<!-- end extra head -->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
|
||||
<link rel="stylesheet" type="text/css" href="../../_static/basic.css" />
|
||||
<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 data-url_root="../../" id="documentation_options" 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/custom.js"></script>
|
||||
<script src="../../_static/settings.js"></script>
|
||||
<script src="../../_static/copy.js"></script>
|
||||
<script src="../../_static/sidebar.js"></script>
|
||||
<link rel="shortcut icon" href="../../_static/discord_py_logo.ico"/>
|
||||
<link rel="index" title="Index" href="../../genindex.html" />
|
||||
<link rel="search" title="Search" href="../../search.html" />
|
||||
<link rel="next" title="API Reference" href="../../api.html" />
|
||||
<link rel="prev" title="API Reference" href="../commands/api.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/TvqYBrGXEm" 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="Search" 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="../../index.html">discord</option>
|
||||
<option value="../commands/index.html" >discord.ext.commands</option>
|
||||
<option value="#" selected>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">Table of Contents</a></h3>
|
||||
<ul>
|
||||
<li><a class="reference internal" href="#"><code class="docutils literal notranslate"><span class="pre">discord.ext.tasks</span></code> – asyncio.Task helpers</a><ul>
|
||||
<li><a class="reference internal" href="#recipes">Recipes</a></li>
|
||||
<li><a class="reference internal" href="#api-reference">API Reference</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</aside>
|
||||
<main class="grid-item" role="main">
|
||||
|
||||
<section id="discord-ext-tasks-asyncio-task-helpers">
|
||||
<span id="discord-ext-tasks"></span><h1><code class="docutils literal notranslate"><span class="pre">discord.ext.tasks</span></code> – asyncio.Task helpers<a class="headerlink" href="#discord-ext-tasks-asyncio-task-helpers" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 1.1.0.</span></p>
|
||||
</div>
|
||||
<p>One of the most common operations when making a bot is having a loop run in the background at a specified interval. This pattern is very common but has a lot of things you need to look out for:</p>
|
||||
<ul class="simple">
|
||||
<li><p>How do I handle <a class="reference external" href="https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.CancelledError" title="(in Python v3.9)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">asyncio.CancelledError</span></code></a>?</p></li>
|
||||
<li><p>What do I do if the internet goes out?</p></li>
|
||||
<li><p>What is the maximum number of seconds I can sleep anyway?</p></li>
|
||||
</ul>
|
||||
<p>The goal of this discord.py extension is to abstract all these worries away from you.</p>
|
||||
<section id="recipes">
|
||||
<h2>Recipes<a class="headerlink" href="#recipes" title="Permalink to this headline">¶</a></h2>
|
||||
<p>A simple background task in a <a class="reference internal" href="../commands/api.html#discord.ext.commands.Cog" title="discord.ext.commands.Cog"><code class="xref py py-class docutils literal notranslate"><span class="pre">Cog</span></code></a>:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">discord.ext</span> <span class="kn">import</span> <span class="n">tasks</span><span class="p">,</span> <span class="n">commands</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">MyCog</span><span class="p">(</span><span class="n">commands</span><span class="o">.</span><span class="n">Cog</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">printer</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">cog_unload</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">printer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
|
||||
|
||||
<span class="nd">@tasks</span><span class="o">.</span><span class="n">loop</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="mf">5.0</span><span class="p">)</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">printer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">)</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Adding an exception to handle during reconnect:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">asyncpg</span>
|
||||
<span class="kn">from</span> <span class="nn">discord.ext</span> <span class="kn">import</span> <span class="n">tasks</span><span class="p">,</span> <span class="n">commands</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">MyCog</span><span class="p">(</span><span class="n">commands</span><span class="o">.</span><span class="n">Cog</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">bot</span> <span class="o">=</span> <span class="n">bot</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">batch_update</span><span class="o">.</span><span class="n">add_exception_type</span><span class="p">(</span><span class="n">asyncpg</span><span class="o">.</span><span class="n">PostgresConnectionError</span><span class="p">)</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">batch_update</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">cog_unload</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">batch_update</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
|
||||
|
||||
<span class="nd">@tasks</span><span class="o">.</span><span class="n">loop</span><span class="p">(</span><span class="n">minutes</span><span class="o">=</span><span class="mf">5.0</span><span class="p">)</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">batch_update</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="k">async</span> <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">bot</span><span class="o">.</span><span class="n">pool</span><span class="o">.</span><span class="n">acquire</span><span class="p">()</span> <span class="k">as</span> <span class="n">con</span><span class="p">:</span>
|
||||
<span class="c1"># batch update here...</span>
|
||||
<span class="k">pass</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Looping a certain amount of times before exiting:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">discord.ext</span> <span class="kn">import</span> <span class="n">tasks</span>
|
||||
|
||||
<span class="nd">@tasks</span><span class="o">.</span><span class="n">loop</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="mf">5.0</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">slow_count</span><span class="p">():</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">slow_count</span><span class="o">.</span><span class="n">current_loop</span><span class="p">)</span>
|
||||
|
||||
<span class="nd">@slow_count</span><span class="o">.</span><span class="n">after_loop</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">after_slow_count</span><span class="p">():</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s1">'done!'</span><span class="p">)</span>
|
||||
|
||||
<span class="n">slow_count</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Waiting until the bot is ready before the loop starts:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">discord.ext</span> <span class="kn">import</span> <span class="n">tasks</span><span class="p">,</span> <span class="n">commands</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">MyCog</span><span class="p">(</span><span class="n">commands</span><span class="o">.</span><span class="n">Cog</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">bot</span> <span class="o">=</span> <span class="n">bot</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">printer</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">cog_unload</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">printer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
|
||||
|
||||
<span class="nd">@tasks</span><span class="o">.</span><span class="n">loop</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="mf">5.0</span><span class="p">)</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">printer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">)</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>
|
||||
|
||||
<span class="nd">@printer</span><span class="o">.</span><span class="n">before_loop</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">before_printer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s1">'waiting...'</span><span class="p">)</span>
|
||||
<span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">bot</span><span class="o">.</span><span class="n">wait_until_ready</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Doing something during cancellation:</p>
|
||||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">discord.ext</span> <span class="kn">import</span> <span class="n">tasks</span><span class="p">,</span> <span class="n">commands</span>
|
||||
<span class="kn">import</span> <span class="nn">asyncio</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">MyCog</span><span class="p">(</span><span class="n">commands</span><span class="o">.</span><span class="n">Cog</span><span class="p">):</span>
|
||||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">bot</span><span class="o">=</span> <span class="n">bot</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">_batch</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">lock</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">Lock</span><span class="p">()</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">bulker</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
||||
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">do_bulk</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="c1"># bulk insert data here</span>
|
||||
<span class="o">...</span>
|
||||
|
||||
<span class="nd">@tasks</span><span class="o">.</span><span class="n">loop</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="mf">10.0</span><span class="p">)</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">bulker</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="k">async</span> <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
||||
<span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">do_bulk</span><span class="p">()</span>
|
||||
|
||||
<span class="nd">@bulker</span><span class="o">.</span><span class="n">after_loop</span>
|
||||
<span class="k">async</span> <span class="k">def</span> <span class="nf">on_bulker_cancel</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulker</span><span class="o">.</span><span class="n">is_being_cancelled</span><span class="p">()</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_batch</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
|
||||
<span class="c1"># if we're cancelled and we have some data left...</span>
|
||||
<span class="c1"># let's insert it to our database</span>
|
||||
<span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">do_bulk</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="api-reference">
|
||||
<span id="ext-tasks-api"></span><h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="py-attribute-table" data-move-to-id="discord.ext.tasks.Loop"><div class="py-attribute-table-column">
|
||||
<span>
|
||||
Attributes</span><ul>
|
||||
<li class="py-attribute-table-entry">
|
||||
<a class="reference internal" href="#discord.ext.tasks.Loop.current_loop">current_loop</a></li><li class="py-attribute-table-entry">
|
||||
<a class="reference internal" href="#discord.ext.tasks.Loop.hours">hours</a></li><li class="py-attribute-table-entry">
|
||||
<a class="reference internal" href="#discord.ext.tasks.Loop.minutes">minutes</a></li><li class="py-attribute-table-entry">
|
||||
<a class="reference internal" href="#discord.ext.tasks.Loop.next_iteration">next_iteration</a></li><li class="py-attribute-table-entry">
|
||||
<a class="reference internal" href="#discord.ext.tasks.Loop.seconds">seconds</a></li><li class="py-attribute-table-entry">
|
||||
<a class="reference internal" href="#discord.ext.tasks.Loop.time">time</a></li></ul>
|
||||
</div><div class="py-attribute-table-column">
|
||||
<span>
|
||||
Methods</span><ul>
|
||||
<li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="coroutine">
|
||||
async</span><a class="reference internal" href="#discord.ext.tasks.Loop.__call__">__call__</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.add_exception_type">add_exception_type</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="decorator">
|
||||
@</span><a class="reference internal" href="#discord.ext.tasks.Loop.after_loop">after_loop</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="decorator">
|
||||
@</span><a class="reference internal" href="#discord.ext.tasks.Loop.before_loop">before_loop</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.cancel">cancel</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.change_interval">change_interval</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.clear_exception_types">clear_exception_types</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="decorator">
|
||||
@</span><a class="reference internal" href="#discord.ext.tasks.Loop.error">error</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.failed">failed</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.get_task">get_task</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.is_being_cancelled">is_being_cancelled</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.is_running">is_running</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.remove_exception_type">remove_exception_type</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.restart">restart</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.start">start</a></li><li class="py-attribute-table-entry">
|
||||
<span class="py-attribute-table-badge" title="method">
|
||||
def</span><a class="reference internal" href="#discord.ext.tasks.Loop.stop">stop</a></li></ul>
|
||||
</div></div><dl class="py class">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop">
|
||||
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">discord.ext.tasks.</span></span><span class="sig-name descname"><span class="pre">Loop</span></span><a class="headerlink" href="#discord.ext.tasks.Loop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A background task helper that abstracts the loop and reconnection logic for you.</p>
|
||||
<p>The main interface to create this is through <a class="reference internal" href="#discord.ext.tasks.loop" title="discord.ext.tasks.loop"><code class="xref py py-func docutils literal notranslate"><span class="pre">loop()</span></code></a>.</p>
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.after_loop">
|
||||
<span class="sig-prename descclassname"><span class="pre">@</span></span><span class="sig-name descname"><span class="pre">after_loop</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.after_loop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A decorator that register a coroutine to be called after the loop finished running.</p>
|
||||
<p>The coroutine must take no arguments (except <code class="docutils literal notranslate"><span class="pre">self</span></code> in a class context).</p>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>This coroutine is called even during cancellation. If it is desirable
|
||||
to tell apart whether something was cancelled or not, check to see
|
||||
whether <a class="reference internal" href="#discord.ext.tasks.Loop.is_being_cancelled" title="discord.ext.tasks.Loop.is_being_cancelled"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_being_cancelled()</span></code></a> is <code class="docutils literal notranslate"><span class="pre">True</span></code> or not.</p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><p><strong>coro</strong> (<a class="reference external" href="https://docs.python.org/3/library/asyncio-task.html#coroutine" title="(in Python v3.9)"><span class="xref std std-ref">coroutine</span></a>) – The coroutine to register after the loop finishes.</p>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#TypeError" title="(in Python v3.9)"><strong>TypeError</strong></a> – The function was not a coroutine.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.before_loop">
|
||||
<span class="sig-prename descclassname"><span class="pre">@</span></span><span class="sig-name descname"><span class="pre">before_loop</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.before_loop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A decorator that registers a coroutine to be called before the loop starts running.</p>
|
||||
<p>This is useful if you want to wait for some bot state before the loop starts,
|
||||
such as <a class="reference internal" href="../../api.html#discord.Client.wait_until_ready" title="discord.Client.wait_until_ready"><code class="xref py py-meth docutils literal notranslate"><span class="pre">discord.Client.wait_until_ready()</span></code></a>.</p>
|
||||
<p>The coroutine must take no arguments (except <code class="docutils literal notranslate"><span class="pre">self</span></code> in a class context).</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><p><strong>coro</strong> (<a class="reference external" href="https://docs.python.org/3/library/asyncio-task.html#coroutine" title="(in Python v3.9)"><span class="xref std std-ref">coroutine</span></a>) – The coroutine to register before the loop runs.</p>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#TypeError" title="(in Python v3.9)"><strong>TypeError</strong></a> – The function was not a coroutine.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.error">
|
||||
<span class="sig-prename descclassname"><span class="pre">@</span></span><span class="sig-name descname"><span class="pre">error</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.error" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A decorator that registers a coroutine to be called if the task encounters an unhandled exception.</p>
|
||||
<p>The coroutine must take only one argument the exception raised (except <code class="docutils literal notranslate"><span class="pre">self</span></code> in a class context).</p>
|
||||
<p>By default this prints to <a class="reference external" href="https://docs.python.org/3/library/sys.html#sys.stderr" title="(in Python v3.9)"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> however it could be
|
||||
overridden to have a different implementation.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 1.4.</span></p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><p><strong>coro</strong> (<a class="reference external" href="https://docs.python.org/3/library/asyncio-task.html#coroutine" title="(in Python v3.9)"><span class="xref std std-ref">coroutine</span></a>) – The coroutine to register in the event of an unhandled exception.</p>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#TypeError" title="(in Python v3.9)"><strong>TypeError</strong></a> – The function was not a coroutine.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.seconds">
|
||||
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">seconds</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.seconds" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Read-only value for the number of seconds
|
||||
between each iteration. <code class="docutils literal notranslate"><span class="pre">None</span></code> if an explicit <code class="docutils literal notranslate"><span class="pre">time</span></code> value was passed instead.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 2.0.</span></p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Type</dt>
|
||||
<dd class="field-odd"><p>Optional[<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>]</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.minutes">
|
||||
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">minutes</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.minutes" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Read-only value for the number of minutes
|
||||
between each iteration. <code class="docutils literal notranslate"><span class="pre">None</span></code> if an explicit <code class="docutils literal notranslate"><span class="pre">time</span></code> value was passed instead.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 2.0.</span></p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Type</dt>
|
||||
<dd class="field-odd"><p>Optional[<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>]</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.hours">
|
||||
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">hours</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.hours" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Read-only value for the number of hours
|
||||
between each iteration. <code class="docutils literal notranslate"><span class="pre">None</span></code> if an explicit <code class="docutils literal notranslate"><span class="pre">time</span></code> value was passed instead.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 2.0.</span></p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Type</dt>
|
||||
<dd class="field-odd"><p>Optional[<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>]</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.time">
|
||||
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">time</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.time" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Read-only list for the exact times this loop runs at.
|
||||
<code class="docutils literal notranslate"><span class="pre">None</span></code> if relative times were passed instead.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 2.0.</span></p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Type</dt>
|
||||
<dd class="field-odd"><p>Optional[List[<a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.time" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a>]]</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.current_loop">
|
||||
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">current_loop</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.current_loop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The current iteration of the loop.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Type</dt>
|
||||
<dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a></p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.next_iteration">
|
||||
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">next_iteration</span></span><a class="headerlink" href="#discord.ext.tasks.Loop.next_iteration" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>When the next iteration of the loop will occur.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 1.3.</span></p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Type</dt>
|
||||
<dd class="field-odd"><p>Optional[<a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a>]</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.__call__">
|
||||
<em class="property"><span class="pre">await</span> </em><span class="sig-name descname"><span class="pre">__call__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.__call__" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>This function is a <a class="reference external" href="https://docs.python.org/3/library/asyncio-task.html#coroutine"><em>coroutine</em></a>.</p>
|
||||
<p>Calls the internal callback that the task holds.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 1.6.</span></p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>*args</strong> – The arguments to use.</p></li>
|
||||
<li><p><strong>**kwargs</strong> – The keyword arguments to use.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.start">
|
||||
<span class="sig-name descname"><span class="pre">start</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.start" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Starts the internal task in the event loop.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>*args</strong> – The arguments to use.</p></li>
|
||||
<li><p><strong>**kwargs</strong> – The keyword arguments to use.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#RuntimeError" title="(in Python v3.9)"><strong>RuntimeError</strong></a> – A task has already been launched and is running.</p>
|
||||
</dd>
|
||||
<dt class="field-odd">Returns</dt>
|
||||
<dd class="field-odd"><p>The task that has been created.</p>
|
||||
</dd>
|
||||
<dt class="field-even">Return type</dt>
|
||||
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/asyncio-task.html#asyncio.Task" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a></p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.stop">
|
||||
<span class="sig-name descname"><span class="pre">stop</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.stop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Gracefully stops the task from running.</p>
|
||||
<p>Unlike <a class="reference internal" href="#discord.ext.tasks.Loop.cancel" title="discord.ext.tasks.Loop.cancel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cancel()</span></code></a>, this allows the task to finish its
|
||||
current iteration before gracefully exiting.</p>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>If the internal function raises an error that can be
|
||||
handled before finishing then it will retry until
|
||||
it succeeds.</p>
|
||||
<p>If this is undesirable, either remove the error handling
|
||||
before stopping via <a class="reference internal" href="#discord.ext.tasks.Loop.clear_exception_types" title="discord.ext.tasks.Loop.clear_exception_types"><code class="xref py py-meth docutils literal notranslate"><span class="pre">clear_exception_types()</span></code></a> or
|
||||
use <a class="reference internal" href="#discord.ext.tasks.Loop.cancel" title="discord.ext.tasks.Loop.cancel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cancel()</span></code></a> instead.</p>
|
||||
</div>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 1.2.</span></p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.cancel">
|
||||
<span class="sig-name descname"><span class="pre">cancel</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.cancel" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Cancels the internal task, if it is running.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.restart">
|
||||
<span class="sig-name descname"><span class="pre">restart</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.restart" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A convenience method to restart the internal task.</p>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>Due to the way this function works, the task is not
|
||||
returned like <a class="reference internal" href="#discord.ext.tasks.Loop.start" title="discord.ext.tasks.Loop.start"><code class="xref py py-meth docutils literal notranslate"><span class="pre">start()</span></code></a>.</p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>*args</strong> – The arguments to use.</p></li>
|
||||
<li><p><strong>**kwargs</strong> – The keyword arguments to use.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.add_exception_type">
|
||||
<span class="sig-name descname"><span class="pre">add_exception_type</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">exceptions</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.add_exception_type" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Adds exception types to be handled during the reconnect logic.</p>
|
||||
<p>By default the exception types handled are those handled by
|
||||
<a class="reference internal" href="../../api.html#discord.Client.connect" title="discord.Client.connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">discord.Client.connect()</span></code></a>, which includes a lot of internet disconnection
|
||||
errors.</p>
|
||||
<p>This function is useful if you’re interacting with a 3rd party library that
|
||||
raises its own set of exceptions.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><p><strong>*exceptions</strong> (Type[<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a>]) – An argument list of exception classes to handle.</p>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#TypeError" title="(in Python v3.9)"><strong>TypeError</strong></a> – An exception passed is either not a class or not inherited from <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a>.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.clear_exception_types">
|
||||
<span class="sig-name descname"><span class="pre">clear_exception_types</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.clear_exception_types" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Removes all exception types that are handled.</p>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>This operation obviously cannot be undone!</p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.remove_exception_type">
|
||||
<span class="sig-name descname"><span class="pre">remove_exception_type</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">exceptions</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.remove_exception_type" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Removes exception types from being handled during the reconnect logic.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><p><strong>*exceptions</strong> (Type[<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a>]) – An argument list of exception classes to handle.</p>
|
||||
</dd>
|
||||
<dt class="field-even">Returns</dt>
|
||||
<dd class="field-even"><p>Whether all exceptions were successfully removed.</p>
|
||||
</dd>
|
||||
<dt class="field-odd">Return type</dt>
|
||||
<dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a></p>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.get_task">
|
||||
<span class="sig-name descname"><span class="pre">get_task</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.get_task" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Optional[<a class="reference external" href="https://docs.python.org/3/library/asyncio-task.html#asyncio.Task" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a>]: Fetches the internal task or <code class="docutils literal notranslate"><span class="pre">None</span></code> if there isn’t one running.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.is_being_cancelled">
|
||||
<span class="sig-name descname"><span class="pre">is_being_cancelled</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.is_being_cancelled" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Whether the task is being cancelled.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.failed">
|
||||
<span class="sig-name descname"><span class="pre">failed</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.failed" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a>: Whether the internal task has failed.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 1.2.</span></p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.is_running">
|
||||
<span class="sig-name descname"><span class="pre">is_running</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.is_running" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a>: Check if the task is currently running.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 1.4.</span></p>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.Loop.change_interval">
|
||||
<span class="sig-name descname"><span class="pre">change_interval</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seconds</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">minutes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hours</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">time</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.Loop.change_interval" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Changes the interval for the sleep time.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 1.2.</span></p>
|
||||
</div>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>seconds</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>) – The number of seconds between every iteration.</p></li>
|
||||
<li><p><strong>minutes</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>) – The number of minutes between every iteration.</p></li>
|
||||
<li><p><strong>hours</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>) – The number of hours between every iteration.</p></li>
|
||||
<li><p><strong>time</strong> (Union[<a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.time" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a>, Sequence[<a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.time" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a>]]) – <p>The exact times to run this loop at. Either a non-empty list or a single
|
||||
value of <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.time" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a> should be passed.
|
||||
This cannot be used in conjunction with the relative time parameters.</p>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 2.0.</span></p>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>Duplicate times will be ignored, and only run once.</p>
|
||||
</div>
|
||||
</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><ul class="simple">
|
||||
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.9)"><strong>ValueError</strong></a> – An invalid value was given.</p></li>
|
||||
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#TypeError" title="(in Python v3.9)"><strong>TypeError</strong></a> – An invalid value for the <code class="docutils literal notranslate"><span class="pre">time</span></code> parameter was passed, or the
|
||||
<code class="docutils literal notranslate"><span class="pre">time</span></code> parameter was passed in conjunction with relative time parameters.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py function">
|
||||
<dt class="sig sig-object py" id="discord.ext.tasks.loop">
|
||||
<span class="sig-prename descclassname"><span class="pre">discord.ext.tasks.</span></span><span class="sig-name descname"><span class="pre">loop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seconds</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">...</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">minutes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">...</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hours</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">...</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">time</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">...</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reconnect</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">loop</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#discord.ext.tasks.loop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>A decorator that schedules a task in the background for you with
|
||||
optional reconnect logic. The decorator returns a <a class="reference internal" href="#discord.ext.tasks.Loop" title="discord.ext.tasks.Loop"><code class="xref py py-class docutils literal notranslate"><span class="pre">Loop</span></code></a>.</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters</dt>
|
||||
<dd class="field-odd"><ul class="simple">
|
||||
<li><p><strong>seconds</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>) – The number of seconds between every iteration.</p></li>
|
||||
<li><p><strong>minutes</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>) – The number of minutes between every iteration.</p></li>
|
||||
<li><p><strong>hours</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>) – The number of hours between every iteration.</p></li>
|
||||
<li><p><strong>time</strong> (Union[<a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.time" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a>, Sequence[<a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.time" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a>]]) – <p>The exact times to run this loop at. Either a non-empty list or a single
|
||||
value of <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.time" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a> should be passed. Timezones are supported.
|
||||
If no timezone is given for the times, it is assumed to represent UTC time.</p>
|
||||
<p>This cannot be used in conjunction with the relative time parameters.</p>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>Duplicate times will be ignored, and only run once.</p>
|
||||
</div>
|
||||
<div class="versionadded">
|
||||
<p><span class="versionmodified added">New in version 2.0.</span></p>
|
||||
</div>
|
||||
</p></li>
|
||||
<li><p><strong>count</strong> (Optional[<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>]) – The number of loops to do, <code class="docutils literal notranslate"><span class="pre">None</span></code> if it should be an
|
||||
infinite loop.</p></li>
|
||||
<li><p><strong>reconnect</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a>) – Whether to handle errors and restart the task
|
||||
using an exponential back-off algorithm similar to the
|
||||
one used in <a class="reference internal" href="../../api.html#discord.Client.connect" title="discord.Client.connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">discord.Client.connect()</span></code></a>.</p></li>
|
||||
<li><p><strong>loop</strong> (<a class="reference external" href="https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoop</span></code></a>) – The loop to use to register the task, if not given
|
||||
defaults to <a class="reference external" href="https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.get_event_loop()</span></code></a>.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
<dt class="field-even">Raises</dt>
|
||||
<dd class="field-even"><ul class="simple">
|
||||
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.9)"><strong>ValueError</strong></a> – An invalid value was given.</p></li>
|
||||
<li><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#TypeError" title="(in Python v3.9)"><strong>TypeError</strong></a> – The function was not a coroutine, an invalid value for the <code class="docutils literal notranslate"><span class="pre">time</span></code> parameter was passed,
|
||||
or <code class="docutils literal notranslate"><span class="pre">time</span></code> parameter was passed in conjunction with relative time parameters.</p></li>
|
||||
</ul>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd></dl>
|
||||
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
</main>
|
||||
<footer class="grid-item">
|
||||
© Copyright 2015-present, Rapptz.
|
||||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.2.0.
|
||||
</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>
|
||||
Reference in New Issue
Block a user