Discord.py Invalid arguments inside member.server_default_channel

試著忘記壹切 提交于 2019-12-02 16:48:15

问题


My current code is

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

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?


回答1:


Default channels no longer exist. This means 2 things:

  1. server.default_channel may return a NoneType.
  2. Trying to send a message to server may raise discord.NotFound.

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.




回答2:


Default channels are not a thing anymore.



来源:https://stackoverflow.com/questions/46673995/discord-py-invalid-arguments-inside-member-server-default-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!