【发布时间】:2021-12-10 03:27:27
【问题描述】:
这是我的代码。当用户加入服务器时,它应该向频道发送消息。
@client.event
async def on_member_join(member):
print('+') #this works perfectly
ch = client.get_channel(84319995256905728)
await ch.send(f"{member.name} has joined")
但是发生了错误。这是输出:
Ignoring exception in on_member_join
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/client.py", line 351, in _run_event
await coro(*args, **kwargs)
File "main.py", line 30, in on_member_join
await ch.send(f"{member.name} has joined")
AttributeError: 'NoneType' object has no attribute 'send'
我在开发门户中启用了服务器成员意图。
intents = nextcord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='=',intents=intents)
我可以知道如何解决它吗?
【问题讨论】:
-
对
client.get_channel()的调用失败并返回None。所以ch不是你想的那样。 -
我认为您应该能够从成员对象的公会属性中获取加入的频道。参考这个example。
-
R U 确定存在具有此类 ID (84319995256905728) 的频道吗?
-
@Alex 是的,频道不存在。感谢您的评论
-
@BoarGules 是的,频道不存在。感谢您的评论
标签: python python-3.x discord discord.py