如何在 Python Discord.py 中设置数据库 [英] How to Setup Database in Python Discord.py

查看:26
本文介绍了如何在 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('
Logged 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 {}
{}'.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆