forked from TakashiJose/TuffyHacks-DiscordBotDemoPublic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
106 lines (92 loc) · 2.78 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#IMPORT: importing discord bot libraries
import discord
from discord.ext import commands
#IMPORT: importing random generator
import random
import os
import json
client = commands.Bot(command_prefix='.')
token = open("token.txt")
TOKEN = token.read()
#EVENT: when the client is ready
@client.event
async def on_ready():
print('Client running')
#EVENT: when a message is received
@client.event
async def on_message(ctx):
#checks if sender of the message is the client/bot
if ctx.author == client.user:
return
#check if its not a command
if ctx.content.startswith('.') == False:
#checks if the user sends a message with 'monke' inside it
if ctx.content.find("monke") !=-1:
await ctx.channel.send(file=discord.File('monke.jpg'))
else:
await ctx.channel.send(ctx.content)
#allows commands to be read.ima
await client.process_commands(ctx)
#EVENT: when the prefix is used, but not a proper command is used
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommmandNotFound):
await ctx.send('Invalid command')
#COMMAND: hello, will respond with 'world'
@client.command()
async def hello(ctx):
"""Send text message 'world'"""
await ctx.send("world")
return
#COMMAND: happy, will respond with the slight_smile emoji
@client.command()
async def happy(ctx):
"""Send :slight_smile: Emoji"""
await ctx.send(":slight_smile:")
return
#COMMAND: dice, will send value found by random generation
@client.command()
async def dice(ctx, arg):
"""Roll Dice(.dice help to see options"""
dice_result=0
if arg == "help":
await ctx.send(".dice <dicetype>")
await ctx.send("dicetype: d4, d6, d8, d10, d12, d20")
return
#d4 rol
if arg == "d4":
dice_result = random.randint(1,4)
if arg == "d6":
dice_result = random.randint(1,6)
if arg == "d8":
dice_result = random.randint(1,8)
if arg == "d10":
dice_result = random.randint(1,10)
if arg == "d12":
dice_result = random.randint(1,12)
if arg == "d20":
dice_result = random.randint(1,20)
await ctx.send(dice_result)
return
#COMMAND: find, will send a capybara image
@client.command()
async def image(ctx):
"""Sends an amazing image"""
await ctx.send(file=discord.File('capybara.jpg'))
return
#COMMAND: boomerang, will repeat the argument if an argument is sent by the user
@client.command()
async def boomerang(ctx, *, arg):
if arg:
await ctx.send(arg)
return
#COG EXTENSION management
#COMMAND: reload, will reload extension
@client.command()
async def reload(ctx):
"""Reloads cog: world"""
client.reload_extension('world')
#loads COG EXTENSION
client.load_extension('world')
#RUN: run client
client.run(TOKEN)