Closed chrisderwahre closed 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.
@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?
The implementation is for you to decide, see Server.channels
.
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
@tilda Ok thanks, but how can send a message when it found a channel to send a message?
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')
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.
@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).
Yes. I see. I would recommend trying these:
The problem with number 2 is that not all guilds will have a #general
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.
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