I'm making a function that looks for a person by his server's nickname and use it to find the data in the SQLite database.
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)
When I tested it there were 3 people online: me (not the owner), the bot, and the test account, and 3 people offline. The bot does not see members except my account, so prints only one nickname and then shows the error.
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'
Today (one day after) the bot does not print even my account name, only one None
and then the error. Why does that happen, how to fix it?