{"id":296532,"date":"2019-12-28T03:00:13","date_gmt":"2019-12-28T03:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=296532"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=296532","title":{"rendered":"Discord \u0431\u043e\u0442 \u0441 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043a\u043e\u0439 \u0441 sqlite"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/482290\/\">\n<h2>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/h2>\n<p>  \u0425\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c, \u043a\u0430\u043a \u044f \u043f\u0438\u0441\u0430\u043b \u0431\u043e\u0442\u0430 c \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043a\u043e\u0439 \u0434\u043b\u044f discord \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c sqlite \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u043b\u043e\u0447\u0438.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u044d\u0442\u0430\u043f<\/h2>\n<p>  <\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u043e\u0442\u0430<\/h4>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u0442\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d:<\/p>\n<ol>\n<li>\u041f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442 <a href=\"https:\/\/discordapp.com\/developers\/applications\/\">\u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432<\/a><\/li>\n<li>\u041d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u00abNew Application\u00bb \u0438 \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0431\u043e\u0442\u0430<\/li>\n<li>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0431\u043e\u0442\u0430, \u0432\u043e\u0439\u0434\u044f \u0432 \u0432\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430 \u0438 \u043d\u0430\u0439\u0434\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u00abSettings\u00bb \u0432\u043a\u043b\u0430\u0434\u043a\u0443 \u00abBot\u00bb<\/li>\n<\/ol>\n<p>  <\/p>\n<h4>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438<\/h4>\n<p>  \u041a\u0430\u043a-\u043d\u0438\u043a\u0430\u043a \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043d\u0430 python, \u0430 \u043d\u0435 \u043d\u0430 ASM, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u0431\u0443\u0434\u0443\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438<\/p>\n<pre><code class=\"bash\">$ pip install discord.py #\u0441\u0430\u043c\u043e api \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u043e\u0442\u043e\u043c<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"bash\">$ pip install tabulate #\u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446<\/code><\/pre>\n<p>  <\/p>\n<h2>\u042d\u0442\u0430\u043f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f<\/h2>\n<p>  <\/p>\n<h4>\u0418\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/h4>\n<p>  \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u0438 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043d\u0430 HTML+CSS.<\/p>\n<pre><code class=\"python\">import sqlite3 #\u043c\u043e\u0434\u0443\u043b\u044c sqlite import discord #\u043c\u043e\u0434\u0443\u043b\u044c discord api from discord.ext import commands #\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 from tabulate import tabulate #\u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0434\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 import json #\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u044f, \u043d\u043e \u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u0434\u0440\u0443\u0433\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a sqlite<\/h4>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"python\">conn = sqlite3.connect(&quot;Discord.db&quot;) # \u0438\u043b\u0438 :memory: cursor = conn.cursor() <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>  \u0412 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 2 \u0442\u0430\u0431\u043b\u0438\u0446\u044b shop \u0438 users.<\/p>\n<pre><code class=\"sql\">CREATE TABLE &quot;shop&quot; ( \t&quot;id&quot;\tINT, \t&quot;type&quot;\tTEXT, \t&quot;name&quot;\tTEXT, \t&quot;cost&quot;\tINT ) <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE TABLE &quot;users&quot; ( \t&quot;id&quot;\tINT, \t&quot;nickname&quot;\tTEXT, \t&quot;mention&quot;\tTEXT, \t&quot;money&quot;\tINT, \t&quot;rep_rank&quot;\tTEXT, \t&quot;inventory&quot;\tTEXT, \t&quot;lvl&quot;\tINT, \t&quot;xp&quot;\tINT ) <\/code><\/pre>\n<p>  <\/p>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043b\u043e\u0433\u0438\u043a\u0438 \u0431\u043e\u0442\u0430<\/h4>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e bot.<\/p>\n<pre><code class=\"python\">bot = commands.Bot(command_prefix=&quot;_&quot;)#\u0432 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 command_prefix \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0437\u043d\u0430\u043a, \u0431\u0443\u043a\u0432\u0443, \u0441\u043b\u043e\u0432\u043e, \u0441\u043b\u043e\u0432\u043e\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u0438 \u0442.\u0434.<\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0446\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430.<\/p>\n<pre><code class=\"python\">bot.run(&quot;\u0417\u0434\u0435\u0441\u044c \u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u043e\u0442\u0430&quot;)<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0447\u043d\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430.<\/p>\n<pre><code class=\"python\">bot = commands.Bot(command_prefix=&quot;_&quot;) #\u0417\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430 bot.run(&quot;\u0417\u0434\u0435\u0441\u044c \u0442\u043e\u043a\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u043e\u0442\u0430&quot;) <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u0438\u0448\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 on_ready(), \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0435\u0435 \u0437\u0430 \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u044c \u0431\u043e\u0442\u0430.<\/p>\n<pre><code class=\"python\">@bot.event async def on_ready():     print(&quot;Bot Has been runned&quot;)#\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u0438     for guild in bot.guilds:#\u0442.\u043a. \u0431\u043e\u0442 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0442\u043e \u0438 \u0446\u0438\u043a\u043b \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u0434\u0438\u043d \u0441\u0435\u0440\u0432\u0435\u0440         print(guild.id)#\u0432\u044b\u0432\u043e\u0434 id \u0441\u0435\u0440\u0432\u0435\u0440\u0430         serv=guild#\u0431\u0435\u0437 \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e         for member in guild.members:#\u0446\u0438\u043a\u043b, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432             cursor.execute(f&quot;SELECT id FROM users where id={member.id}&quot;)#\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a \u0432 \u0411\u0414             if cursor.fetchone()==None:#\u0415\u0441\u043b\u0438 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442                 cursor.execute(f&quot;INSERT INTO users VALUES ({member.id}, '{member.name}', '&lt;@{member.id}&gt;', 50000, 'S','[]',0,0)&quot;)#\u0432\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0435 \u0432 \u0411\u0414             else:#\u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442                 pass             conn.commit()#\u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0411\u0414 <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u043e\u0438\u0442, \u0447\u0442\u043e\u0431\u044b \u043b\u0438\u0448\u043d\u0438\u0439 \u0440\u0430\u0437 \u043d\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0431\u043e\u0442\u0430, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 on_member_join()<\/p>\n<pre><code class=\"python\">@bot.event async def on_member_join(member):     cursor.execute(f&quot;SELECT id FROM users where id={member.id}&quot;)#\u0432\u0441\u0435 \u0442\u0430\u043a\u0436\u0435, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a \u0432 \u0411\u0414     if cursor.fetchone()==None:#\u0415\u0441\u043b\u0438 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442         cursor.execute(f&quot;INSERT INTO users VALUES ({member.id}, '{member.name}', '&lt;@{member.id}&gt;', 50000, 'S','[]',0,0)&quot;)#\u0432\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0435 \u0432 \u0411\u0414     else:#\u0415\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442         pass     conn.commit()#\u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0411\u0414 <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0431\u043e\u0442 \u0443 \u043d\u0430\u0441 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439, \u0437\u043d\u0430\u0447\u0438\u0442 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u0430\u043b\u044e\u0442\u0430, \u0435\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u043e\u043a \u0438 \u0435\u0435 \u0442\u0440\u0430\u0442\u0430. \u0417\u0430\u0440\u0430\u0431\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e experience \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<pre><code class=\"python\">@bot.event async def on_message(message):     if len(message.content) &gt; 10:#\u0437\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u043e\u0439 &gt; 10 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432...         for row in cursor.execute(f&quot;SELECT xp,lvl,money FROM users where id={message.author.id}&quot;):             expi=row[0]+random.randint(5, 40)#\u043a \u043e\u043f\u044b\u0442\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e             cursor.execute(f'UPDATE users SET xp={expi} where id={message.author.id}')             lvch=expi\/(row[1]*1000)             print(int(lvch))             lv=int(lvch)             if row[1] &lt; lv:#\u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u0440\u043e\u0432\u043d\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u0444\u043e\u0440\u043c\u0443\u043b\u043e\u0439 \u0432\u044b\u0448\u0435,...                 await message.channel.send(f'\u041d\u043e\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c!')#\u0442\u043e \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435...                 bal=1000*lv                 cursor.execute(f'UPDATE users SET lvl={lv},money={bal} where id={message.author.id}')#\u0438 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0435\u043d\u044c\u0433\u0438     await bot.process_commands(message)#\u0414\u0430\u043b\u0435\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f ctx \u043a\u043e\u043c\u0430\u043d\u0434     conn.commit()#\u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0411\u0414 <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0443 \u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u043e \u0442\u0438\u043f\u0443 \u0430\u043a\u043a\u0430\u0443\u043d\u0442, \u043c\u0430\u0433\u0430\u0437\u0438\u043d \u0438 \u0442.\u0434. \u0414\u0443\u043c\u0430\u044e \u0434\u0430\u043b\u044c\u0448\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<pre><code class=\"python\">@bot.command() async def account(ctx): #\u043a\u043e\u043c\u0430\u043d\u0434\u0430 _account (\u0433\u0434\u0435 &quot;_&quot;, \u0432\u0430\u0448 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u044b\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435)     table=[[&quot;nickname&quot;,&quot;money&quot;,&quot;lvl&quot;,&quot;xp&quot;]]     for row in cursor.execute(f&quot;SELECT nickname,money,lvl,xp FROM users where id={ctx.author.id}&quot;):         table.append([row[0],row[1],row[2],row[3]])         await ctx.send(f&quot;&gt;\\n{tabulate(table)}&quot;)  @bot.command() async def inventory(ctx):#\u043a\u043e\u043c\u0430\u043d\u0434\u0430 _inventory (\u0433\u0434\u0435 &quot;_&quot;, \u0432\u0430\u0448 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u044b\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435)      counter=0     for row in cursor.execute(f&quot;SELECT inventory FROM users where id={ctx.author.id}&quot;):         data=json.loads(row[0])         table=[[&quot;id&quot;,&quot;type&quot;,&quot;name&quot;]]         for row in data:             prt=row             for row in cursor.execute(f&quot;SELECT id,type,name FROM shop where id={prt}&quot;):                 counter+=1                 table.append([row[0],row[1],row[2]])                                  if counter==len(data):                     await ctx.send(f'&gt;\\n{tabulate(table)}')   @bot.command() async def shop(ctx):#\u043a\u043e\u043c\u0430\u043d\u0434\u0430 _shop (\u0433\u0434\u0435 &quot;_&quot;, \u0432\u0430\u0448 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u044b\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435)     counter=0     table=[[&quot;id&quot;,&quot;type&quot;,&quot;name&quot;,&quot;cost&quot;]]     for row in cursor.execute(f&quot;SELECT id,type,name,cost FROM shop&quot;):         counter+=1         table.append([row[0],row[1],row[2],row[3]])         if counter==4:             await ctx.send(f'&gt;\\n{tabulate(table)}') <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043c\u0430\u0433\u0430\u0437\u0438\u043d, \u0437\u043d\u0430\u0447\u0438\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u044c? \u041d\u0435 \u0442\u0430\u043a-\u043b\u0438?<\/p>\n<pre><code class=\"python\">async def buy(ctx, a: int):     uid=ctx.author.id     await ctx.send('\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430... \u0415\u0441\u043b\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0443\u043a\u0430\u0437\u0430\u043d \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 id \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430 [buy {id}]')     for row in cursor.execute(f&quot;SELECT money FROM users where id={uid}&quot;):         money = row[0]         for row in cursor.execute(f&quot;SELECT id,name,cost FROM shop where id={a}&quot;):             cost=row[2]             if money &gt;= cost:#\u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0435\u043d\u0435\u0433,\u0442\u043e...                 money -=cost                 await ctx.send(f'\u0412\u044b \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u043b\u0438 &quot;{row[1]}&quot; \u0437\u0430 {row[2]}')                                  for row in cursor.execute(f&quot;SELECT inventory FROM users where id={uid}&quot;):                     data=json.loads(row[0])                     data.append(a)                     daed=json.dumps(data)                     cursor.execute('UPDATE users SET money=?,inventory = ? where id=?',(money,daed,uid))#\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0432\u0430\u043c \u0432 \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u044c                     pass             if money &lt; cost:#\u0438\u043d\u0430\u0447\u0435 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0435                 await ctx.send(f'\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432')                 pass     conn.commit()#\u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0411\u0414 <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0431\u043e\u0442 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u044d\u0442\u043e \u043a\u043e\u043c\u0443-\u043b\u0438\u0431\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442.<\/p>\n<p>  \u042f \u043f\u043e\u043d\u0438\u043c\u0430\u044e \u0447\u0442\u043e \u0432 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e (\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e) \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0444\u0438\u0448\u0435\u043a, \u043d\u043e \u044d\u0442\u043e \u0433\u043e\u043b\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u0438\u0447\u043a\u0438 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 discord.py, \u043c\u043e\u0434\u0443\u043b\u044c sqlite \u0438 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b python.<\/p>\n<p>  \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u0414\u043e \u0441\u0432\u044f\u0437\u0438!<\/p><\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/482290\/\"> https:\/\/habr.com\/ru\/post\/482290\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/482290\/\">\n<h2>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/h2>\n<p>  \u0425\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c, \u043a\u0430\u043a \u044f \u043f\u0438\u0441\u0430\u043b \u0431\u043e\u0442\u0430 c \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043a\u043e\u0439 \u0434\u043b\u044f discord \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c sqlite \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u043b\u043e\u0447\u0438.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-296532","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/296532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=296532"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/296532\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=296532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=296532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=296532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}