python-3.x - 运行时出现错误“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:
解决方案
guild
可以None
听到在 DM 通道中执行的代码。
这些可能是一个很好的选择:
- 使用频道成员:
channel = ctx.channel
for member in channel.members:
...
- 使用支票:
# ---------- 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
推荐阅读
- python-3.x - 添加新数据时列表框自行调整大小
- c# - 通过 Azure 函数显示来自 Azure Blob 存储的文件
- javascript - 我可以在我的 console.log 中显示 API 数据,但我不能用它来设置状态。. . 我该如何设置状态?(获取,反应本机)
- anaconda - 无法创建虚拟环境
- angular - 错误设置宽度 - 错误:ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改
- python - 即使在输入 if -else 的 else 之后,return 语句在 Python 中也不起作用?
- reactjs - 如何隐藏反应引导模式并调用保存功能?
- ibm-cloud - IBM Watson Assistant:如何添加超过 5 个技能?
- database - 缺少右括号第 1 行
- xcode - SwiftUI 2.0 TabView 禁用滑动以更改页面