Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.73k stars 3.74k forks source link

on_server_join(server) error #969

Closed chrisderwahre closed 6 years ago

chrisderwahre commented 6 years ago

Hey im getting this issue when my bot joins the server. This is my Code: @client.event async def on_server_join(server): em = Embed(title='Invited', description='Text.', colour=discord.Color.gold()) await client.send_message(server, embed=em)

And this is the Error: discord.errors.NotFound: NOT FOUND (status code: 404): Unknown Channel

Im using Python 3.5

LucasCoderT commented 6 years ago

The documentation stating that you can use a server as a destination in send_message is out of date, as it implies the server has a default channel, which not every server will have. You will need to explicitly state which channel to send too.

chrisderwahre commented 6 years ago

@datmellow Sounds bad. I just changed it that the bot send the server owner a DM, or is there any way to send a message to a random channel?

LucasCoderT commented 6 years ago

The implementation is for you to decide, see Server.channels.

tilda commented 6 years ago

You could go through the first channel which the bot can write to.

async def find_channel(guild):
    """
    Finds a suitable guild channel for posting the
    welcome message.
    """
    for c in guild.text_channels:
        if not c.permissions_for(guild.me).send_messages:
            continue
        return c
chrisderwahre commented 6 years ago

@tilda Ok thanks, but how can send a message when it found a channel to send a message?

tilda commented 6 years ago

It returns a discord.Channel, so you store it in a variable and use it.

# Replace guild with whatever variable that you use for a server
channel = await find_channel(guild)
# Send a message to the channel that was found
await channel.send('blah')
modelmat commented 6 years ago

You could also use http://discordpy.readthedocs.io/en/rewrite/api.html#discord.Guild.system_channel (the default channel for welcome messages. However, this might not always be set.

tilda commented 6 years ago

@Modelmat Yeah, that's mostly why we use my find_channel function here. It finds the "default channel" (first one it can speak in, aka highest).

modelmat commented 6 years ago

Yes. I see. I would recommend trying these:

  1. Default welcome channel (system channel)
  2. Finding #general and checking for perms
  3. Iterating over sendable channels
NCPlayz commented 6 years ago

The problem with number 2 is that not all guilds will have a #general

modelmat commented 6 years ago

That's why we try the general channel.

On 31/12/2017, at 0:04, Nadir Chowdhury notifications@github.com wrote:

The problem with #2 is that not all guilds will have a #general

― You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.