问题描述
我当前的代码是
@client.event
async def on_member_join(member):
serverchannel = member.server.default_channel
msg = "Wuss poppin', {0}. Welcome to {1}".format(member.mention, member.server.name)
await client.send_message(member.server.default_channel, msg)`
@client.event
async def on_member_remove(member):
serverchannel = member.server.default_channel
msg = "Well. Cya, {0}!".format(member.mention)
await client.send_message(serverchannel, msg)
以及其他必要的行(例如import discord
等)和其他命令.
As well as the other necessary lines (like import discord
etc.) and other commands.
当成员加入或离开时,出现此错误:
When a member joins or leaves, I get this error:
Ignoring exception in on_member_join
Traceback (most recent call last):
File "C:\Users\WillL\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:/Users/WillL/Desktop/MemzBot-master/index.py", line 102, in on_member_join
await client.send_message(member.server.default_channel, msg)
File "C:\Users\WillL\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 1145, in send_message
channel_id, guild_id = yield from self._resolve_destination(destination)
File "C:\Users\WillL\AppData\Local\Programs\Python\Python36\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
我不明白为什么,我想念什么?
I don't understand why, what am I missing?
推荐答案
默认渠道不再存在.这意味着两件事:
-
server.default_channel
可能返回NoneType. - 尝试向
server
发送消息可能会提高discord.NotFound
.
server.default_channel
may return a NoneType.- Trying to send a message to
server
may raisediscord.NotFound
.
这些情况将发生在8月3日之后创建的任何服务器上,或者已删除其默认"频道的任何服务器上.
These cases will happen on any servers created after August 3rd, or any servers who have deleted their "default" channel.
您需要自己选择一个频道,或要求服务器为欢迎消息设置频道.您仍然可以尝试发送到服务器,但是如果失败,请确保有一个后备选项.
You need to either choose a channel yourself, or ask the server to set a channel for the welcome message. You can still attempt to send to the server, but make sure you have a fall back option if it fails.
这篇关于Discord.py member.server_default_channel内部无效的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!