【问题标题】:Bot does not see members on serverBot 在服务器上看不到成员
【发布时间】:2021-05-07 22:52:14
【问题描述】:

我正在制作一个函数,它通过服务器的昵称查找一个人,并使用它在 SQLite 数据库中查找数据。

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) 

当我测试它时,有 3 个人在线:我(不是所有者)、机器人和测试帐户,以及 3 个人离线。 bot 看不到除我的帐户以外的成员,因此只打印一个昵称,然后显示错误。

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'

今天(一天后)机器人甚至不打印我的帐户名,只打印一个None,然后是错误。为什么会发生这种情况,如何解决?

【问题讨论】:

  • 请发布更多代码
  • 你需要启用intents.members,看看this answer
  • @ŁukaszKwieciński 我做到了,但没有帮助。顺便说一句,版本是 1.6.0

标签: python discord discord.py


【解决方案1】:

str(memb.nick).lower()代替memb.nick.lower()

【讨论】:

    猜你喜欢
    • 2021-01-21
    • 2021-09-03
    • 2021-07-19
    • 2021-07-05
    • 2021-05-09
    • 2021-02-22
    • 2022-01-16
    • 2015-01-20
    • 2021-06-18
    相关资源
    最近更新 更多