【问题标题】:when run it gives error 'NoneType' object has no attribute 'members'运行时出现错误“NoneType”对象没有属性“成员”
【发布时间】:2021-12-01 13:39:46
【问题描述】:

这是我的代码

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:

【问题讨论】:

  • 错误意味着guildsd1对象是None

标签: python-3.x discord


【解决方案1】:

在 DM 频道中执行的代码 guildNone 听到。
这些可能是一个不错的选择:

  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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-21
    • 2021-10-28
    • 1970-01-01
    • 2017-09-14
    • 2021-02-17
    • 2023-02-17
    • 1970-01-01
    • 2020-05-20
    相关资源
    最近更新 更多