-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
57 lines (41 loc) · 1.51 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# bot.py
import os
import random
import discord
import typing
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='.')
@bot.event
async def on_ready():
print('Connected as ' + str(bot.user) + ' to guilds: \n' + str(bot.guilds))
@bot.event
async def on_member_join(member):
role = discord.utils.get(member.guild.roles, name='Player')
await member.add_roles(role)
@bot.command(name='roll')
async def roll(ctx, max: typing.Optional[int] = 20):
embed = discord.Embed(
#title = 'Dice Roll',
colour = discord.Colour.red()
)
response = str(random.randint(1,max))
#await ctx.send('Rolled a D' + str(max) + ' and got: ' + response)
author = ''
if ctx.author.nick:
author = ctx.author.nick
else:
author = ctx.author.name
embed.set_footer(text='Rolled by '+ str(author),icon_url=str(ctx.author.avatar_url))
embed.set_author(name='Dice Roll',icon_url='https://cdn.pixabay.com/photo/2017/08/31/04/01/d20-2699387_960_720.png')
embed.add_field(name='Dice', value='D'+str(max),inline=True)
embed.add_field(name='Result',value=response,inline=True)
await ctx.send(embed=embed)
await ctx.message.delete()
@roll.error
async def roll_error(ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send('Must only be 1 argument and argument must be a whole number')
bot.run(TOKEN)