【问题标题】:psycopg2.ProgrammingError: can't adapt type 'set'psycopg2.ProgrammingError:无法适应类型“设置”
【发布时间】:2020-10-31 03:36:14
【问题描述】:

有这个不和谐的机器人。我不想为我的服务器创建。但我使用 psycopg2 是因为我不想用它来创建项目创意列表。我收到了这个错误psycopg2.ProgrammingError: can't adapt type 'set' 这是我的代码:

import psycopg2
import os
from discord.ext import commands
import discord

conn = psycopg2.connect(
        host="ec2-3-216-92-193.compute-1.amazonaws.com",
        database="d1vpende403347",
        user="hnzgmwsoiogmmt",
        password="86bfca0c982e04ae0ca6e6f4d1f4fb03ca5f4f4cb9a911672fa993a300e7ea0e",
        port=5432)
bot=discord.Client()
bot=commands.Bot(command_prefix="!")
cursor=conn.cursor()

@bot.command()
async def rules(ctx):
    await ctx.send("1. To enter our server, you have of course to learn python and some libraries, for example: 'discord.py', 'django'.\n2. No insults or bad words.\n3.Enjoy it.")
@bot.command()
async def new(ctx, author:discord.Member, project):
    name=author.display_name
    await ctx.send(f"There is your entry: The author: {name} , project: {project}")
    cursor.execute(f"INSERT INTO ideas(author,project) VALUES(%s,%s)",({name},{project}))
    await ctx.send("The entry was succesfully added""")

print("And There it is, you're connected")

TOKEN=os.environ.get("DISCORD_BOT_SECRET")
bot.run(TOKEN)

cursor.close()
conn.close()

感谢回复

【问题讨论】:

标签: python discord psycopg2


【解决方案1】:
import psycopg2
import os
from discord.ext import commands
import discord

conn = psycopg2.connect(
        host="ec2-3-216-92-193.compute-1.amazonaws.com",
        database="d1vpende403347",
        user="hnzgmwsoiogmmt",
        password="86bfca0c982e04ae0ca6e6f4d1f4fb03ca5f4f4cb9a911672fa993a300e7ea0e",
        port=5432)
bot=discord.Client()
bot=commands.Bot(command_prefix="!")
cursor=conn.cursor()

@bot.command()
async def rules(ctx):
    await ctx.send("1. To enter our server, you have of course to learn python and some libraries, for example: 'discord.py', 'django'.\n2. No insults or bad words.\n3.Enjoy it.")
@bot.command()
async def new(ctx, author:discord.Member, project):
    name=author.display_name
    await ctx.send(f"There is your entry: The author: {name} , project: {project}")
    cursor.execute(f"INSERT INTO ideas(author,project) VALUES(%s,%s)",(name,project))
    await ctx.send("The entry was succesfully added""")

print("And There it is, you're connected")

TOKEN=os.environ.get("DISCORD_BOT_SECRET")
bot.run(TOKEN)

cursor.close()
conn.close()

【讨论】:

  • 就是答案
  • 当您发布答案时,如果您描述修复程序会更有帮助,而不是仅仅使用模组重新发布代码块,尤其是像这样的相当大的块。我最终不得不在两个浏览器窗口中加载它们并逐行比较——即使这样也很难发现差异。只是说...
猜你喜欢
  • 1970-01-01
  • 2021-08-08
  • 2019-11-10
  • 2020-08-21
  • 1970-01-01
  • 2016-10-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多