forked from dinxsh/Ayane-San
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
134 lines (108 loc) · 5 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
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
import discord
import os
import asyncio
from discord.ext import tasks, commands
from discord.utils import get
from itertools import cycle
prefix = '!'
bot = commands.Bot(command_prefix = prefix)
bot.remove_command('help')
status = cycle(["listening to yo mom", "listening to !help", "UwU"])
#|--------------------EVENTS--------------------|
@bot.event
async def on_ready():
#Enter any startup tasks here
change_status.start()
#This is printed in the console to notify the user that the bot is running correctly without error
print("Bot is ready to use.")
@bot.event
async def on_member_join(member):
print(f'Welcome {member.mention}!, glad to have you here!')
@bot.event
async def on_message(message):
if prefix in message.content:
print("This is a command")
await bot.process_commands(message)
else:
# with open("words_blacklist.txt") as bf:
# blacklist = [word.strip().lower() for word in bf.readlines()]
# bf.close()
# blacklist words here
channel = message.channel
await bot.process_commands(message)
#This event waits for commands to be issued, if a specific command requires a permission or arguement
#This event will be invoked to tell the user that they dont have the required permissions
#or they havent issues the command correctly
@bot.event
async def on_command_error(context, error):
if isinstance(error, commands.MissingRequiredArgument):
await context.send("Oh no! Looks like you have missed out an argument for this command.")
if isinstance(error, commands.MissingPermissions):
await context.send("Oh no! Looks like you Dont have the permissions for this command.")
if isinstance(error, commands.MissingRole):
await context.send("Oh no! Looks like you Dont have the roles for this command.")
#bot errors
if isinstance(error, commands.BotMissingPermissions):
await context.send("Oh no! Looks like I Dont have the permissions for this command.")
if isinstance(error, commands.BotMissingRole):
await context.send("Oh no! Looks like I Dont have the roles for this command.")
#|------------------COMMANDS------------------|
@bot.command()
async def help(message):
helpC = discord.Embed(title="moderator Bot \nHelp Guide", description="discord bot built for moderation")
helpC.set_thumbnail(url='https://i.imgur.com/ZOKp8LH.png')
helpC.add_field(name="clear", value="To use this command type !clear and the number of messages you would like to delete, the default is 5.", inline=False)
helpC.add_field(name="kick/ban/unban", value="To use this command type !kick, !ban, !unban then mention the user you would like to perform this on, NOTE: user must have permissions to use this command.", inline=False)
await message.channel.send(embed=helpC)
@bot.command()
@commands.has_permissions(manage_messages=True)
async def clear(context, amount=5):
await context.channel.purge(limit=amount+1)
@bot.command()
@commands.has_permissions(kick_members=True)
async def kick(context, member : discord.Member, *, reason=None):
await member.kick(reason=reason)
await context.send(f'Member {member} has been kicked')
@bot.command()
@commands.has_permissions(ban_members=True)
async def ban(context, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await context.send(f'{member} has been banned')
@bot.command()
async def calc(context, *, equation):
await context.send(f'Answer: ' + eval(equation))
#Unbanning a member is done via typing ./unban and the ID of the banned member
@bot.command()
@commands.has_permissions(ban_members=True)
async def unban(context, id : int):
user = await bot.fetch_user(id)
await context.guild.unban(user)
await context.send(f'{user.name} has been unbanned')
#Bans a member for a specific number of days
@bot.command()
@commands.has_permissions(ban_members=True)
async def softban(context, member : discord.Member, days, reason=None):
#Asyncio uses seconds for its sleep function
#multiplying the num of days the user enters by the num of seconds in a day
days * 86400
await member.ban(reason=reason)
await context.send(f'{member} has been softbanned')
await asyncio.sleep(days)
print("Time to unban")
await member.unban()
await context.send(f'{member} softban has finished')
#This command will add a word to the blacklist to prevent users from typing that specific word
@bot.command()
@commands.has_permissions(ban_members=True)
async def blacklist_add(context, *, word):
with open("words_blacklist.txt", "a") as f:
f.write("\n"+word)
f.close()
await context.send(f'Word "{word}" added to blacklist.')
#|------------------TASKS------------------|
#This is a task which runs every 5 seconds
@tasks.loop(seconds=5)
async def change_status():
#This loops through the status variable at the top of this file every 5 seconds
await bot.change_presence(activity=discord.Game(next(status)))
bot.run('BOT_TOKEN_HERE')