'NoneType'对象没有属性'send'



这是我的代码。当用户加入服务器时,应该向通道发送消息。

@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)  

我可以知道如何修理它吗?

确保您的bot有能力在该通道中发送消息,否则它会说它不能发送消息,如果它确实确保通道Id存在。例如:

@client.event
async def on_member_join(member):
channel = client.get_channel(900247143351210004)
await channel.send(f"{member.mention} has arrived!, check out our announcments channel for server and bot announcements!")

感谢大家的意见。以上问题已处理好。问题是id为84319995256905728的频道不存在,我相应地修复了它。

相关内容

  • 没有找到相关文章

最新更新