我仍在学习discord.py库,因此对任何菜鸟错误都深表歉意。
下面的代码是执行3个动作的函数的一部分:
- 连接到
sqlite3
数据库 - 询问要创建的套件名称,并将新的套件名称插入
sqlite3
数据库中 - 询问用户是否要将卡添加到他们的套件名称中。
#To create a new kit
@client.command(name="createkit")
async def createkit(message):
author = message.author
await author.send("What name would you like to give the new kit?")
msg = await client.wait_for('message')
kitName = msg.content #name of kit user wants to make
userID = msg.author.id #User ID of the author of the reply message
username = msg.author.name #username of the author who wrote the reply message
db = sqlite3.connect('kits.sqlite')
cursor = db.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS kits(
DeckID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,User TEXT NOT NULL,UserID INTEGER NOT NULL,Deckname TEXT NOT NULL
)
''')
print("Connected to Kits")
cursor.execute(f"SELECT * FROM kits WHERE UserID = {userID}")
sql = ("INSERT INTO kits(User,UserID,Deckname) VALUES(?,?,?)")
val = (username,userID,kitName)
cursor.execute(sql,val)
db.commit()
await author.send(f"{kitName} has been created!")
addCards = await author.send(f"Would you like to add cards to {kitName}?")
await addCards.add_reaction('?')
await addCards.add_reaction('?')
reaction,user = await client.wait_for('reaction_add')
if user == client.user:
return
elif str(reaction.emoji) == '?':
print(user)
await user.send('Great!') #<-- error
print("Replied with thumbs up!")
elif str(reaction.emoji) == '?':
await user.send('Too bad...') #<-- error
print("Replied with thumbs down!")
cursor.close()
db.close()```
第1部分和第2部分可以正常工作。第3部分要求用户对竖起大拇指或表情符号的表情符号做出反应,从而引发以下错误:
discord.ext.commands.errors.CommandInvokeError:
Command raised an exception: AttributeError:
'ClientUser' object has no attribute 'send'
这很奇怪,我将重新启动bot并执行命令使用。我将以竖起大拇指的表情符号做出反应,并回复“很棒!”不会产生任何错误。我将再次运行它,并以不赞成或不赞成的方式答复,并发生上述错误。它似乎是第一次工作,但是第二次却出错了。即使我在不久后重新启动bot,它也会失败。如果我在重新启动之前稍等片刻,然后再试一次,则该漫游器将运行一次,然后每次都失败,并出现相同的问题。我不确定是什么问题。我查看了其他一些似乎无法解决该问题的线程。
非常感谢您提前提供的帮助!