你好,我是这个数据库设置的新手,我对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)
答案 0 :(得分:0)
仅此阅读asyncpg文档。 您的问题尚不清楚,因为“设置Postgresql数据库帐户”不是Python或discord.py问题。