問題描述
我當(dāng)前的代碼是
@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.
當(dāng)成員加入或離開時,我收到此錯誤:
When a member joins or leaves, I get this error:
Ignoring exception in on_member_join
Traceback (most recent call last):
File "C:UsersWillLAppDataLocalProgramsPythonPython36libsite-packagesdiscordclient.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:UsersWillLAppDataLocalProgramsPythonPython36libsite-packagesdiscordclient.py", line 1145, in send_message
channel_id, guild_id = yield from self._resolve_destination(destination)
File "C:UsersWillLAppDataLocalProgramsPythonPython36libsite-packagesdiscordclient.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
發(fā)送消息可能會引發(fā)discord.NotFound
.
server.default_channel
may return a NoneType.- Trying to send a message to
server
may raisediscord.NotFound
.
這些情況將發(fā)生在 8 月 3 日之后創(chuàng)建的任何服務(wù)器上,或者任何已刪除其默認"頻道的服務(wù)器上.
These cases will happen on any servers created after August 3rd, or any servers who have deleted their "default" channel.
您需要自己選擇一個頻道,或者要求服務(wù)器為歡迎消息設(shè)置一個頻道.您仍然可以嘗試發(fā)送到服務(wù)器,但請確保您有一個失敗的后備選項.
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.
這篇關(guān)于Discord.py member.server_default_channel 中的參數(shù)無效的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!