我不明白我的 on_member_join/on_member_remove 函数遇到的这些错误
I don't understand these errors im getting with my on_member_join/on_member_remove functions
我一直在研究 python 中编码的 discord 机器人。而且我一直在尝试让我的机器人在用户加入服务器和离开服务器时说出消息。但是当我测试它时,我得到了 2 个错误,我不明白这些错误。我不确定我做错了什么。如果有人可以帮助解释这些错误,并为我的代码指出正确的方向,我将不胜感激。
我研究了 discord 重写 api 并在我的服务器上和一个朋友一起测试了它,结果出现了错误
@client.event
async def on_member_join(member):
channel = member.server.get_channel("499457708978864151")
msg = 'Welcome to the {1.name} Server, {0.mention}'
await client.say(channel, msg.format(member, member.server))
@client.event
async def on_member_remove(member):
channel = member.server.get_channel("499457708978864151")
msg = '{0.mention} has left the server'
await client.say((channel, msg.format(member, member.server)))
我希望我的机器人说欢迎来到(服务器名称)服务器,当他们进入服务器时@username,当用户离开时@username 已经离开服务器但我收到这些错误:
TypeError: send_message() takes from 2 to 3 positional arguments but 4 were given
discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType
这是我的完整回溯
Ignoring exception in on_member_join
Traceback (most recent call last):
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Chris/PycharmProjects/untitled1/RomaniBot.py", line 37, in on_member_join
await client.say(channel, msg.format(member, member.server))
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\ext\commands\bot.py", line 350, in say
coro = self.send_message(destination, *args, **kwargs)
TypeError: send_message() takes from 2 to 3 positional arguments but 4 were given
Ignoring exception in on_member_remove
Traceback (most recent call last):
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Chris/PycharmProjects/untitled1/RomaniBot.py", line 43, in on_member_remove
await client.say((channel, msg.format(member, member.server)))
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\ext\commands\bot.py", line 309, in _augmented_msg
msg = yield from coro
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 1145, in send_message
channel_id, guild_id = yield from self._resolve_destination(destination)
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 289, in _resolve_destination
raise InvalidArgument(fmt.format(destination))
discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType
一个简单的代码修复方法是使用 channel.send
而不是 client.say
。所以
@client.event
async def on_member_join(member):
channel = member.server.get_channel(499457708978864151)
msg = 'Welcome to the {1.name} Server, {0.mention}'
await channel.send(msg.format(member, member.server))
此外,根据文档,
get_channel(id)
Returns a abc.GuildChannel or abc.PrivateChannel with
the following ID.
If not found, returns None.
所以你没有select频道成功。原因是rewrite中的ID是一个int
,不是字符串
member.server
returns你的服务器,会员加入的地方。并且您尝试访问 ID 为 499457708978864151
的频道,除了频道 ID 为 499457708978864151
的服务器之外,这肯定无法在其他服务器上工作,因此您也必须获取服务器 [=13] =] 会这样做。
我一直在研究 python 中编码的 discord 机器人。而且我一直在尝试让我的机器人在用户加入服务器和离开服务器时说出消息。但是当我测试它时,我得到了 2 个错误,我不明白这些错误。我不确定我做错了什么。如果有人可以帮助解释这些错误,并为我的代码指出正确的方向,我将不胜感激。
我研究了 discord 重写 api 并在我的服务器上和一个朋友一起测试了它,结果出现了错误
@client.event
async def on_member_join(member):
channel = member.server.get_channel("499457708978864151")
msg = 'Welcome to the {1.name} Server, {0.mention}'
await client.say(channel, msg.format(member, member.server))
@client.event
async def on_member_remove(member):
channel = member.server.get_channel("499457708978864151")
msg = '{0.mention} has left the server'
await client.say((channel, msg.format(member, member.server)))
我希望我的机器人说欢迎来到(服务器名称)服务器,当他们进入服务器时@username,当用户离开时@username 已经离开服务器但我收到这些错误:
TypeError: send_message() takes from 2 to 3 positional arguments but 4 were given
discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType
这是我的完整回溯
Ignoring exception in on_member_join
Traceback (most recent call last):
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Chris/PycharmProjects/untitled1/RomaniBot.py", line 37, in on_member_join
await client.say(channel, msg.format(member, member.server))
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\ext\commands\bot.py", line 350, in say
coro = self.send_message(destination, *args, **kwargs)
TypeError: send_message() takes from 2 to 3 positional arguments but 4 were given
Ignoring exception in on_member_remove
Traceback (most recent call last):
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/Chris/PycharmProjects/untitled1/RomaniBot.py", line 43, in on_member_remove
await client.say((channel, msg.format(member, member.server)))
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\ext\commands\bot.py", line 309, in _augmented_msg
msg = yield from coro
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 1145, in send_message
channel_id, guild_id = yield from self._resolve_destination(destination)
File "C:\Users\Chris\PycharmProjects\untitled1\venv\lib\site-packages\discord\client.py", line 289, in _resolve_destination
raise InvalidArgument(fmt.format(destination))
discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType
一个简单的代码修复方法是使用 channel.send
而不是 client.say
。所以
@client.event
async def on_member_join(member):
channel = member.server.get_channel(499457708978864151)
msg = 'Welcome to the {1.name} Server, {0.mention}'
await channel.send(msg.format(member, member.server))
此外,根据文档,
get_channel(id)
Returns a abc.GuildChannel or abc.PrivateChannel with the following ID.
If not found, returns None.
所以你没有select频道成功。原因是rewrite中的ID是一个int
,不是字符串
member.server
returns你的服务器,会员加入的地方。并且您尝试访问 ID 为 499457708978864151
的频道,除了频道 ID 为 499457708978864151
的服务器之外,这肯定无法在其他服务器上工作,因此您也必须获取服务器 [=13] =] 会这样做。