-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
43 lines (32 loc) · 1.15 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#importing discord.py library
import discord
from discord.ext.commands import Bot
from random import choice
#importing env variables
from dotenv import load_dotenv
import os
#Credentials of bot token
load_dotenv('.env')
bot = Bot("!")
# client = discord.Client()
with open("compliments.txt" , "r") as file:
complimentList = list(file)
def getCompliment():
return choice(complimentList)
@bot.event #Indicates that on_ready() comes under client event
async def on_ready():
print("We have logged in")
@bot.event
async def on_message(message):
print(message.author, message.content, message.channel)
if message.content[0] != '!' :
if message.author != bot.user:
await message.channel.send(message.content + " " + str(message.author)) #await is for the program to wait till the message.send is completed
await bot.process_commands(message)
@bot.command(pass_context=True)
async def compliment(ctx, member:discord.Member):
complimentToSend = getCompliment()
complimentToSend += member.mention
await ctx.send(complimentToSend)
#Running the bot
bot.run(os.getenv('COMPLIMENT_BOT_TOKEN'))