Skip to content

Instantly share code, notes, and snippets.

@swang373
Last active October 24, 2019 15:59
Show Gist options
  • Save swang373/08e293b08338517308c1f8f4ce1721ab to your computer and use it in GitHub Desktop.
Save swang373/08e293b08338517308c1f8f4ce1721ab to your computer and use it in GitHub Desktop.
Awaiting bot mentions using discord.py
import logging
import discord
logger = logging.getLogger('DiscordBot')
class Bot(discord.Client):
def __init__(self):
super().__init__()
async def on_ready(self):
logger.info(f'Logged in as {self.user.name} with ID {self.user.id}')
async def on_message(self, message):
# Have the bot ignore its own messages.
if message.author == self.user:
return
# If a message mentions the bot, do something potentially useful.
if self.user in message.mentions:
await message.channel.send(f'{message.mentions}')
if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s %(levelname)s [%(name)s] %(message)s', level=logging.INFO)
bot = Bot()
bot.run('YourDiscordBotTokenGoesHere')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment