如何在Python Discord.py中设置数据库 [英] How to Setup Database in Python Discord.py
本文介绍了如何在Python Discord.py中设置数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我是这个数据库设置的新手,我对python bot中的数据库设置一无所知。我决定将数据库连接添加到我新创建的Postgresql帐户中,以存储用户数据。
Hello I'm new to this database setup i don't know anything about database setup in python bot. I decided to add a database connection to my Postgresql account which i been created newly to store user data.
所以我可以获取任何示例完整代码来设置Postgresql数据库帐户。
So can i get any example full code to setup Postgresql database account.
更新这是我的文件代码。
Update this is my file code.
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
prefix = "!"
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import csv
startup_extensions = ["xxxx", "xxxx", "xxxx", "xxxx"]
bot = commands.Bot(command_prefix=prefix)
bot.remove_command("help")
@bot.event
async def on_ready():
print('\nLogged in as')
print("Bot Name: " + bot.user.name)
print("Bot User ID: " + bot.user.id)
@bot.event
async def on_message(message):
message.content = message.content.lower()
await bot.process_commands(message)
@bot.command(pass_context=True)
async def ping(ctx):
msg = "Pong {0.author.mention}".format(ctx.message)
await bot.say(msg)
if __name__ == "__main__":
for extension in startup_extensions:
try:
bot.load_extension(extension)
except Exception as e:
exc = '{}: {}'.format(type(e).__name__, e)
print('Failed to load extension {}\n{}'.format(extension, exc))
bot.run(token)
推荐答案
阅读asyncpg文档,仅此而已。
您的问题尚不清楚,因为设置Postgresql数据库帐户不是Python或discord.py问题。
Read the asyncpg documentation, that's about it. Your Question is not clear enough as to "setup Postgresql database account" is not a Python or discord.py issue.
这篇关于如何在Python Discord.py中设置数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文