play4honor / discord_quote_bot

A bot that brings the "quote" feature to Discord.
2 stars 1 forks source link

Add message on Server Join #11

Closed synsypa closed 5 years ago

synsypa commented 6 years ago

tried to add a message on server join, but didn't work. Should be useful when the bot goes down to indicate revival

@bot.event
@asyncio.coroutine
def on_server_join():
    log.info(log_msg(['bot join', bot.user.name, bot.user.id, 'server', bot.server.id]))

    yield from bot.say('yo, we in there')

    log.info(log_msg(['sent_message', 'server_join', ctx.message.channel.name]))

was my attempt

zhangchuck commented 5 years ago

Potential Strategy:

https://stackoverflow.com/questions/49881606/how-do-i-send-a-message-to-all-text-channels-with-discord-py

Currently, it looks like this:

https://github.com/zhangchuck/discord_quote_bot/blob/79bab28f186c46da8506d6ffc4b0fc1cfb6c7516/discord_quote/discord_quote/discord_quote.py#L55-L60

What is the .next() here for?

Maybe we need something like:

    # Get all channels 
    all_channels = yield from bot.get_all_channels()

    # Iterate through channels
     for channel in all_channels:
         bot.send_message(channel, 'yo, we in there')
zhangchuck commented 5 years ago

Oddly, can't seem to get the on_server_join() event to trigger, even when turning it on in the server settings.

I got it to work by moving it to the on_ready() event.

zhangchuck commented 5 years ago

Addressed in #35