Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
import discord
from discord.ext import commands
from azure.cognitiveservices.search.imagesearch import ImageSearchAPI
from msrest.authentication import CognitiveServicesCredentials
bot = commands.Bot(command_prefix='!', description='A bot to help the user choose a car.')
# Example code from discord.py documentation that I added the change precence function to
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
activity = discord.Activity(name='You Pick A Car', type=discord.ActivityType.watching)
await bot.change_presence(activity=activity)
bot.remove_command('help')
# End of modified example code from discord.py documentation
# Image search api example code that i have modified and intergrated into a discord bot using the discord.py documentation
@bot.event
async def on_message(message):
if message.author == bot.user:
return
else:
subscription_key = ''
search_term = message.content
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key))
image_results = client.images.search(query=search_term)
#await message.channel.send("Searching the web for images of: {}".format(search_term))
if image_results.value:
first_image_result = image_results.value[0]
await message.channel.send(format(first_image_result.content_url))
else:
await message.channel.send("Couldn't find image results!")
# End of image search api example code that I modified
bot.run('')