Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ChatBot/exampleBot.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22 lines (17 sloc)
1.28 KB
This file contains 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 discord | |
from discord.ext import commands #imports discord libary | |
bot = commands.Bot(command_prefix='!', description='A bot to help the user choose a car.') #sets the commannd prefix for the bot, we arent going to use this but it needs to be here to run | |
@bot.event | |
async def on_ready(): #when the bot is ready and connected to discord it runs the following code | |
print('Logged in as') #prints to shell NOT discord | |
print(bot.user.name) | |
print(bot.user.id) | |
activity = discord.Activity(name='You Pick A Car', type=discord.ActivityType.watching) #sets the activity within discord to watching you pick a car | |
await bot.change_presence(activity=activity) #changed the presence | |
bot.remove_command('help') #removes the preset help command as we wont use it | |
@bot.event | |
async def on_message(message): #runs the below code when there is a message in discord | |
if "car" == message.content.lower(): #sets the message content to all lowercase to make it understandable and checks to see if car is the message content | |
await message.channel.send("You want a car") #sends this message to the discord channel where the message was | |
await message.channel.send("This is a car", file=discord.File('a1.png')) | |
bot.run('') #runs the bot using the long token given. |