【问题标题】:How to Setup Database in Python Discord.py如何在 Python Discord.py 中设置数据库
【发布时间】:2018-09-02 01:08:23
【问题描述】:

您好,我是这个数据库设置的新手,我对 python bot 中的数据库设置一无所知。我决定向我新创建的 Postgresql 帐户添加一个数据库连接来存储用户数据。

那么我可以获取任何示例完整代码来设置 Postgresql 数据库帐户。


更新这是我的文件代码。

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)

【问题讨论】:

  • 仍然没有人回答?

标签: python-3.x discord.py


【解决方案1】:

阅读 asyncpg 文档,仅此而已。 您的问题不够清楚,“设置 Postgresql 数据库帐户”不是 Python 或 discord.py 问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 2012-12-19
    • 1970-01-01
    • 2020-12-18
    • 2021-10-23
    • 2011-01-23
    相关资源
    最近更新 更多