-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
71 lines (56 loc) · 2 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
58
59
60
61
62
63
64
65
66
67
68
# bot.py
import os
import random
import constants
import asyncio
import discord
from discord.ext.commands import Bot
from dotenv import load_dotenv
import time
load_dotenv()
bot = Bot(command_prefix='?')
@bot.command(name='roll_dice', help='Simulates rolling dice.')
async def roll(ctx, number_of_dice, number_of_sides):
dice = []
for i in range(int(number_of_dice)):
dice.append(str(random.randint(1,int(number_of_sides))))
await ctx.send(', '.join(dice))
@bot.command(name = 'clear')
async def on_message(ctx, number):
await ctx.channel.purge(limit = int(number))
@bot.command(name = 'checkid')
async def checkid(ctx, user_id):
user = await bot.fetch_user(int(user_id))
print(user)
@bot.command(name ='dm')
async def dm(ctx, user_id, number, message):
user = await bot.fetch_user(int(user_id))
message = message.replace('_', ' ')
print (message)
for i in range(int(number)):
await user.send(message)
print('Recieved')
time.sleep(1)
@bot.command(name = 'skyrim')
async def play_skyrim_sound(ctx):
await ctx.send(file=discord.File('cloud.jpg'))
#Adapted from Thomas Kelly's code on how to play sound in voice channel from:
#https://stackoverflow.com/a/53790124
@bot.command(name = 'error')
async def play_error_sound(ctx):
# Gets voice channel of message author
voice_channel = ctx.author.voice.channel
channel = None
if voice_channel != None:
channel = voice_channel.name
vc = await voice_channel.connect()
vc.play(discord.FFmpegPCMAudio(executable='C:/Users/Lukas/Desktop/Discord Bot/ffmpeg-20200831-4a11a6f-win64-static/ffmpeg-20200831-4a11a6f-win64-static/bin/ffmpeg.exe', source="error.mp3"))
# Sleep while audio is playing.
while vc.is_playing():
time.sleep(.1)
await vc.disconnect()
else:
await ctx.send(str(ctx.author.name) + "is not in a channel.")
# Delete command after the audio is done playing.
await ctx.message.delete()
bot.run(constants.TOKEN)