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.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
import requests
GREETING_KEYWORDS = ("hello", "hi", "greetings", "sup", "good evening","good morning","helo", "bonjour", )##person greet
GREETING_RESPONSES = ["'sup bro", "hey", "good morning", "hello"]##bot greet
DOING_KEYWORDS = ("how are you doing?", "how are you?")##person asks bto how he is
DOING_RESPONSES = ["I'am doing great","I'm doing fine","I'm alright","I'm doing terrible", "I'm doing really bad","I'm doing bad"]##bot can choose to answer
ASKING_ABOUT_YOU = ["And what about you?", "how bout you?","what about you?", "and you?"]##after answering bot asks the same to person
JOKES_KEYWORDS = ["give me jokes", "joke", "can u give me joke?", "can u give me jokes?""can you please give me some jokes?", "jokes","give me some jokes", "please give me some jokes"]
Client = discord.Client() #Initialise Client
client = commands.Bot(command_prefix = "?") #Initialise client bot
@client.event
async def on_ready():
print("Bot is online and connected to Discord") #the think that will be writen when the bot is turn on
@client.event
async def on_message(message):
if client.user == message.author:##the bot response olny to user message
return #return nothing if it is the bot message
greeting = check_for_greeting(message.content)
emoji = check_for_emoji(message.content)
joke = check_for_jokes(message.content)
response = ""
if greeting:
response = greeting
elif emoji:
response = emoji
elif joke:
response = joke
if response:
await client.send_message(message.channel, response)
def check_for_greeting(sentence):
"""if user write anything from the greeting keyword, the bot responce with greeting responce"""
if sentence.lower() in GREETING_KEYWORDS:
return random.choice(GREETING_RESPONSES)
if sentence.lower() in DOING_KEYWORDS:
return random.choice(DOING_RESPONSES) + ", " + random.choice(ASKING_ABOUT_YOU)
def check_for_jokes(sentence):
r = requests.get('https://api.icndb.com/jokes/random')
data = r.json()
ans = data["value"]["joke"]
if sentence.lower() in JOKES_KEYWORDS:
return ans
def check_for_emoji(sentence):
if sentence == "crying":
return (":joy:")
if sentence == "cool":
return (":sunglasses:")
if sentence == "ok":
return (":ok_hand:")
if sentence == "USA":
return (":flag_um:")
if sentence == "UK":
return (":flag_gb:")
if sentence == "really bad":
return (":poop:")
if sentence == "lithuania":
return (":flag_lt:")
if sentence == "kiss":
return (":kissing_heart:")
if sentence == "happy":
return (":smiley:")
if sentence == "angry":
return ( ":imp:")
if sentence == "cookie":
return (":cookie:")
client.run("TOKEN HERE")