我正在制作一个函数,通过他的服务器昵称查找一个人,并用它来查找 SQLite 数据库中的数据。
TypeError: not all arguments converted during string formatting
当我测试它时,有 3 个人在线:我(不是所有者)、机器人和测试帐户,还有 3 个人离线。 机器人除了我的帐户外看不到其他成员,因此只打印一个昵称然后显示错误。
import discord
import datetime
import sqlite3 as sql
from discord.ext import commands
...
#TOKEN and SQLite database lines
...
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix = "{", intents = intents)
@bot.event
async def on_reaction_add(reaction, user):
if isinstance((reaction.message.channel), discord.channel.DMChannel): #it works only in private (DM) channels
msg = reaction.message
channel = msg.channel
guild = bot.get_guild(769858357607399443) #it is a valid ID of the guild with the bot
member = guild.get_member(user.id)
emoji_count = reaction.count
if emoji_count > 1:
if reaction.emoji == "?":
print("test")
elif reaction.emoji == "?":
await channel.send("Enter the person's nickname.")
def check(m):
return m.author.id == user.id
answer = await bot.wait_for("message", check = check)
from there for memb in guild.members:
print(memb.nick)
if memb.nick.lower() == answer.content.lower():
to there member_act = memb
cur.execute(f"SELECT * FROM users WHERE discord_user_id =
{member_act.id};")
data_tuple = cur.fetchall()
data = data_tuple[0]
embed=discord.Embed(title="Name:", description=f"
{member_act.name}", color=0x0037f3)
embed.set_author(name="PG Official Profile Card")
embed.add_field(name = "nice")...
... #just the rest of embed.
await channel.send(embed = embed)
今天(一天后)机器人甚至没有打印我的帐户名,只有一个 Tony_Forlatt ### it is the nickname of my account
None ### the reason of the error
Ignoring exception in on_reaction_add
Traceback (most recent call last):
File "C:\Users\plays\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py",
line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\plays\OneDrive\Рабочий стол\Python\bot2.py", line 227, in on_reaction_add
if memb.nick.lower() == answer.content.lower():
AttributeError: 'NoneType' object has no attribute 'lower'
,然后是错误。为什么会发生这种情况,如何解决?
答案 0 :(得分:0)
用memb.nick.lower()
代替str(memb.nick).lower()