@Corsaka/

CorsakaBot

Python

Basic discord bot.

fork
loading
Files
  • main.py
  • requirements.txt
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
import discord
from discord.ext import commands
from asyncio import sleep
import datetime
# imports

bot = commands.Bot(command_prefix=commands.when_mentioned_or("c?"), description="A cool bot for cool things.",pm_help="None")
# sets the prefix, allows people to mention the bot to call commands

@bot.event
async def on_ready():
  print(bot.user, end='')
  print(" online!")
  await (bot.get_channel(495526646724427776)).send("I'm online as of " + str((datetime.datetime.now()).strftime("%H:%M, %d/%m/%Y")) + ". Hello!")
  # tells a channel that bot is online after recieving confirmation from discord
  await bot.change_presence(activity=discord.Game("c?help"))
  # sets the playing status of the bot

# Moderation Commands
@bot.command()
async def ban(target = ''):
  """Bans a client."""
  if target != '':
    await bot.ban(target,delete_message_days=7)
  else:
    await bot.say("Specify a target to ban.")

@bot.command()
async def kick(target = ''):
  """Kicks a client."""
  if target != '':
    await bot.kick(target)
  else:
    await bot.say("Specify a target to kick.")

@bot.command(pass_context=True)
async def purge(ctx,number : str = ''):
  """Purges messages from a channel."""
  if number != '':
    if int(number) <= 10000:
      await bot.purge_from(channel=ctx.message.channel,limit=int(number))
    else:
      await bot.say("Max 10,000 messages purged.")
  else:
    await bot.say("Specify number of messages to purge.")


# Fun Commands
@bot.command()
async def repeat(content : str = "", times : str = ""):
  """Repeats a message up to 5 times."""
  if content != "":
    if times != "":
      for i in range(int(times)):
        if int(times) <= 5:
          await bot.say(content)
          sleep(0.1)
        else:
          await bot.say("Maximum 5 repeated messages!")
          break;
    else:
      await bot.say("Specify a number of times (max 5) for the bot to repeat `"+ content +"`.")
  else:
    await bot.say("Specify the word you want repeated, and the number of times (max 5).")

# starts bot (@CorsakaBot#5621, <@484474350742011904>)