首页 > 解决方案 > 运行时出现错误“NoneType”对象没有属性“成员”

问题描述

这是我的代码

for member in guildsd.members:
    if author == bot.user:#bot luôn luôn đặt vị trí member của bot ở đầu tiên vậy nên code bot.user sẽ luôn bằng bot của bạn
        return
    if 'member' in content:
        await say(member)
    if 'test' in content:

标签: python-3.xdiscord

解决方案


guild可以None听到在 DM 通道中执行的代码。
这些可能是一个很好的选择:

  1. 使用频道成员:
channel = ctx.channel


for member in channel.members:
    ...
  1. 使用支票:
# ---------- for commands ----------
@guild_only() # from discord.ext.commands
@command()
async def my_command(ctx):
    ctx.guilds # Always is Guild object

# ---------- for events ----------
@client.event
async def on_<event>(..., channel, ...):
    ...
    is not isinstanse(channel, DMChannel):
        ... # channel is on a guild
    else:
        ... # this is DMChannel or GroupChannel

推荐阅读