Last active
October 24, 2019 15:59
-
-
Save swang373/08e293b08338517308c1f8f4ce1721ab to your computer and use it in GitHub Desktop.
Awaiting bot mentions using discord.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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