-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
142 lines (115 loc) · 7.31 KB
/
bot.py
File metadata and controls
142 lines (115 loc) · 7.31 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import discord
import os
from discord.ext import commands, tasks
import random
import itertools
client = commands.Bot(command_prefix='!')
client.remove_command("help")
#On Ready Event------------------------------------------
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.online, activity=discord.Game(" !help"))
print('Logged in as: {0.user}'.format(client))
#General Error Handling----------------------------------
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
command_not_found = discord.Embed(title="Command Not Found :(", description="Use !help to see the list of commands and how to use them.", colour=discord.Colour.orange())
await ctx.send(content=None, embed=command_not_found)
else:
print (error)
#Commands-------------------------------------------------
@client.command(pass_context=True) #Custom Help Command
async def help(ctx):
embed = discord.Embed(title="Help", colour = discord.Colour.orange())
embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/717853456244670509/718950987762761758/SynergyyNoBg.png")
embed.add_field(name='!random', value = 'Randomly chooses an option from the ones you give the bot.\n>>> eg. !random Pizza Taco Sushi Burger', inline=False)
embed.add_field(name='!range', value = 'Randomly chooses a number between the start and end point you define.\n>>> eg. !range 0 500', inline=False)
embed.add_field(name='!shuffle', value = 'Shuffles a sequence that you provide. Use this to easily decide on an order to do an activity.\n>>> eg. !shuffle John Gary Kevin Brian', inline=False)
embed.add_field(name='!8ball', value = 'Ask the magical 8 ball a question!\n>>> eg. !8ball Will France win the next World Cup?', inline=False)
embed.add_field(name='!flip', value = 'Flip a coin!', inline=False)
await ctx.send(embed=embed)
@client.command() #Ping Command
async def ping(ctx):
await ctx.send(f'Pong! My current latency is {round(client.latency*1000)}ms.')
@client.command(aliases=['random']) #Random Command
async def rand(ctx, *information):
output = random.choice(information)
rand_embed = discord.Embed(description=f"The result is: **{output}**!", colour = discord.Colour.orange())
await ctx.send(embed=rand_embed)
@client.command(aliases=['range']) #Range Command
async def rand2(ctx, start, stop):
output = random.randint(int(start), int(stop))
range_embed = discord.Embed(description=f"The result is: **{output}**!", colour = discord.Colour.orange())
await ctx.send(embed=range_embed)
@client.command(aliases=['shuffle']) #Shuffle Command
async def rand3(ctx, *information):
l = list(information)
output = random.sample(l, len(l))
shuffle_embed = discord.Embed(description=f"Shuffled Order: {output}", colour = discord.Colour.orange())
await ctx.send(embed=shuffle_embed)
@client.command() #Coinflip Command
async def flip(ctx):
choices = ["Heads", "Tails"]
rancoin = random.choice(choices)
coinflip_card = discord.Embed(colour = discord.Colour.orange(), description=f"The result was **{rancoin}**!")
await ctx.send(embed=coinflip_card)
@client.command(aliases=['8ball']) #8ball Command
async def _8ball(ctx, *, question):
responses = ["It is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.",
"As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.", "Reply hazy, try again.",
"Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.",
"Don't count on it.", "My reply is no.", "My sources say no.", "Outlook not so good.", "Very doubtful."]
_8ball_card = discord.Embed(colour = discord.Colour.orange(), description = f"**Question:** {question}\n**Answer:** {random.choice(responses)}")
await ctx.send(embed=_8ball_card)
@client.command(pass_context=True)
async def botservers(ctx):
await ctx.send("I'm in " + str(len(client.guilds)) + " servers")
@client.command(pass_context=True)
async def listservers(ctx):
async for guild in client.fetch_guilds(limit=150):
print(guild.name)
#Error Handling ---------
@rand.error
async def rand_error(ctx, error):
unexcpected_error = discord.Embed(title='Unexcpected Error :(', description="Please try again later or refer to !help for more help.", colour=discord.Color.orange())
item_missing = discord.Embed(title='Missing Options!', description="You must provide the bot with options to select from!\n For more help,refer to !help", colour=discord.Color.orange())
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(content=None, embed=item_missing)
else:
print(error)
await ctx.send(content=None, embed=unexcpected_error)
@rand2.error
async def rand2_error(ctx, error):
unexcpected_error = discord.Embed(title='Unexcpected Error :(', description="Please try again later or refer to !help for more help.", colour=discord.Color.orange())
item_missing = discord.Embed(title='Missing Argument!', description="You must enter a beggining and end point for the range!\nFor more help,refer to !help", colour=discord.Color.orange())
bad_argument = discord.Embed(title='Argument Error!', description="There was a problem with the arguments you provided.\nRefer to !help for the correct format.", colour=discord.Color.orange())
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(content=None, embed=item_missing)
elif isinstance(error, commands.BadArgument):
await ctx.send(content=None, embed=bad_argument)
else:
print(error)
await ctx.send(content=None, embed=unexcpected_error)
@rand3.error
async def rand3_error(ctx, error):
unexcpected_error = discord.Embed(title='Unexcpected Error :(', description="Please try again later or refer to !help for more help.", colour=discord.Color.orange())
item_missing = discord.Embed(title='Missing Argument!', description="You must provide a sequence to shuffle!\nFor more help,refer to !help", colour=discord.Color.orange())
bad_argument = discord.Embed(title='Argument Error!', description="There was a problem with the arguments you provided.\nRefer to !help for the correct format.", colour=discord.Color.orange())
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(content=None, embed=item_missing)
elif isinstance(error, commands.BadArgument):
await ctx.send(content=None, embed=bad_argument)
else:
print(error)
await ctx.send(content=None, embed=unexcpected_error)
@_8ball.error
async def _8ball_error(ctx, error):
arg_missing = discord.Embed(title='Missing Required Argument!', description="You need to ask the 8ball a question!\neg. !8ball Am I cool?\n Please refer to !help for more info.", colour=discord.Color.green())
format_error = discord.Embed(title='Format Error!', description="Please follow this format: !8ball Am I cool?\n Please refer to !help for more info.", colour=discord.Color.green())
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(content=None, embed=arg_missing)
else:
await ctx.send(content=None, embed=format_error)
#Bot Token Pairing-----------------------------------------
client.run(os.environ['TOKEN'])