【发布时间】: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