|
| 1 | +""" |
| 2 | +_____ |
| 3 | +___ ___ __ _______ ________ _________ ___ ___ ________ ________ _________ |
| 4 | +|\ __ \|\ \ |\ \|\ ___ \ |\ __ \|\___ ___\ |\ \ / /|\ __ \|\ __ \|\___ ___\ |
| 5 | +\ \ \|\ \ \ \ \ \ \ \ __/|\ \ \|\ \|___ \ \_| \ \ \/ / | \ \|\ /\ \ \|\ \|___ \ \_| |
| 6 | + \ \ \\\ \ \ \ __\ \ \ \ \_|/_\ \ _ _\ \ \ \ \ \ / / \ \ __ \ \ \\\ \ \ \ \ |
| 7 | + \ \ \\\ \ \ \|\__\_\ \ \ \_|\ \ \ \\ \| \ \ \ \/ / / \ \ \|\ \ \ \\\ \ \ \ \ |
| 8 | + \ \_____ \ \____________\ \_______\ \__\\ _\ \ \__\__/ / / \ \_______\ \_______\ \ \__\ |
| 9 | + \|___| \__\|____________|\|_______|\|__|\|__| \|__|\___/ / \|_______|\|_______| \|__| |
| 10 | + \|__| \|___|/ |
| 11 | +
|
| 12 | +""" |
| 13 | + |
| 14 | +#imports |
| 15 | +from ast import Return |
| 16 | +from importlib.resources import contents |
| 17 | +import discord |
| 18 | +import os |
| 19 | +from discord.ext import commands |
| 20 | +import random |
| 21 | +import numpy |
| 22 | +import time |
| 23 | +import re |
| 24 | +import string |
| 25 | +import asyncio |
| 26 | +import json |
| 27 | +import aiohttp |
| 28 | + |
| 29 | +client = discord.Client() |
| 30 | + |
| 31 | +#discord bot token |
| 32 | +TOKEN = 'X' |
| 33 | + |
| 34 | +#Prefix |
| 35 | +bot = commands.Bot(command_prefix="#") |
| 36 | + |
| 37 | + |
| 38 | +#bot status in discord client and server ready message |
| 39 | +@bot.event |
| 40 | +async def on_ready(): |
| 41 | + activity = discord.Game(name="#help", type=3) |
| 42 | + await bot.change_presence(status=discord.Status.idle, activity=activity) |
| 43 | + print("Bot is ready!") |
| 44 | + |
| 45 | +#coinflip |
| 46 | +@bot.command(pass_context=True) |
| 47 | +async def coinflip(ctx): |
| 48 | + """Flip a virtual coin!""" |
| 49 | + variable = [ |
| 50 | + "```Heads!```", |
| 51 | + "```Tails!```",] |
| 52 | + await ctx.channel.send("{}".format(random.choice(variable))) |
| 53 | + |
| 54 | +#dice |
| 55 | +@bot.command(pass_context=True) |
| 56 | +async def dice(ctx): |
| 57 | + """Throws a virtual 6 sided die.""" |
| 58 | + variable = [ |
| 59 | + "```1```", |
| 60 | + "```2```", |
| 61 | + "```3```", |
| 62 | + "```4```", |
| 63 | + "```5```", |
| 64 | + "```6```", |
| 65 | + ] |
| 66 | + await ctx.channel.send("{}".format(random.choice(variable))) |
| 67 | + |
| 68 | +#ping |
| 69 | +@bot.command() |
| 70 | +async def ping(ctx): |
| 71 | + """Check the bot ping!""" |
| 72 | + await ctx.send(f"{client.latency}") |
| 73 | + if round(client.latency * 1000) <= 50: |
| 74 | + embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0x44ff44) |
| 75 | + elif round(client.latency * 1000) <= 100: |
| 76 | + embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0xffd000) |
| 77 | + elif round(client.latency * 1000) <= 200: |
| 78 | + embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0xff6600) |
| 79 | + else: |
| 80 | + embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0x990000) |
| 81 | + await ctx.send(embed=embed) |
| 82 | + |
| 83 | + |
| 84 | +#weclome message dm |
| 85 | +@client.event |
| 86 | +async def on_member_join(member, ctx): |
| 87 | + await ctx.author.send("```Hello there!```") |
| 88 | + |
| 89 | + |
| 90 | +#membercount |
| 91 | +@bot.command() |
| 92 | +async def membercount(ctx): |
| 93 | + """Check the server membercount!""" |
| 94 | + embed = discord.Embed( |
| 95 | + title=('Membercount'), |
| 96 | + description =(f'There are currently **{ctx.guild.member_count}** members in the server!'), |
| 97 | + |
| 98 | + color= discord.Colour.dark_blue() |
| 99 | + ) |
| 100 | + embed.set_footer(text='QWERTY') |
| 101 | + embed.set_thumbnail(url='') |
| 102 | + await ctx.send(embed=embed) |
| 103 | + |
| 104 | + |
| 105 | +#bot-commands |
| 106 | +@bot.command(aliases=['about']) |
| 107 | +async def info(ctx): |
| 108 | + """About the bot!""" |
| 109 | + embed = discord.Embed( |
| 110 | + title=('Info'), |
| 111 | + description =(f'A Discord bot made by QwertyIsThinking#1587 for moderation and for fun! It is self hosted and is made with Discord.py!'), |
| 112 | + |
| 113 | + color= discord.Colour.dark_blue() |
| 114 | + ) |
| 115 | + embed.set_footer(text='QWERTY') |
| 116 | + embed.set_thumbnail(url='') |
| 117 | + await ctx.send(embed=embed) |
| 118 | + |
| 119 | + |
| 120 | +#bot invite |
| 121 | +@bot.command(pass_context=True) |
| 122 | +async def invite(ctx): |
| 123 | + """Invite this bot to your server!""" |
| 124 | + |
| 125 | + embed = discord.Embed( |
| 126 | + title=('Invite'), |
| 127 | + description =(f'Here is the invitation link: https://discord.com/api/oauth2/authorize?client_id=927841410319781908&permissions=449160039488&scope=bot'), |
| 128 | + |
| 129 | + color= discord.Colour.dark_blue() |
| 130 | + ) |
| 131 | + embed.set_footer(text='QWERTY') |
| 132 | + embed.set_thumbnail(url='') |
| 133 | + await ctx.send(embed=embed) |
| 134 | + |
| 135 | +#test the bot to see if it is online |
| 136 | +@bot.command(aliases=['test']) |
| 137 | +async def status(ctx): |
| 138 | + """Is the bot okay?""" |
| 139 | + embed = discord.Embed( |
| 140 | + title=('Status'), |
| 141 | + description =(f'The bot is online and everything SEEMS to be fine!'), |
| 142 | + |
| 143 | + color= discord.Colour.dark_blue() |
| 144 | + ) |
| 145 | + embed.set_footer(text='QWERTY') |
| 146 | + embed.set_thumbnail(url='') |
| 147 | + await ctx.send(embed=embed) |
| 148 | + |
| 149 | +#your discord server invite, in this case, it is my discord server invite |
| 150 | +@bot.command(pass_context=True) |
| 151 | +async def server(ctx): |
| 152 | + """The creator's main server!""" |
| 153 | + await ctx.channel.send('Here is the server invite for main server: https://discord.gg/JE2AfPm2Yu') |
| 154 | + |
| 155 | +#the discord bot support server, you can make your own support server if you are the one hosting it |
| 156 | +@bot.command(pass_context=True) |
| 157 | +async def support(ctx): |
| 158 | + """Support server!""" |
| 159 | + await ctx.channel.send('Here is the support server link: https://discord.gg/7RSxKSaN68') |
| 160 | +@bot.command(pass_context = True) |
| 161 | + |
| 162 | +#owner |
| 163 | +@commands.is_owner() |
| 164 | +async def owner(ctx): |
| 165 | + """Shows if you are the true owner of the bot or not.""" |
| 166 | + await ctx.channel.send('```If you executed this command, then you are the owner of this bot!```') |
| 167 | + |
| 168 | +#badwords filter |
| 169 | +with open('badwords.txt') as file: |
| 170 | + file = file.read().split() |
| 171 | + |
| 172 | +@bot.event |
| 173 | +async def on_message(message): |
| 174 | + mybot = bot.get_user('X') |
| 175 | + |
| 176 | + if message.author is mybot: |
| 177 | + return |
| 178 | + |
| 179 | + flag = False |
| 180 | + for badword in file: |
| 181 | + if badword in message.content.lower(): |
| 182 | + await message.delete() |
| 183 | + await message.channel.send(f'{message.author.mention}! Foul language.') |
| 184 | + flag = True |
| 185 | + |
| 186 | + if not flag: |
| 187 | + await bot.process_commands(message) |
| 188 | + |
| 189 | +#repeat |
| 190 | +@bot.command() |
| 191 | +async def repeat(ctx, *, message): |
| 192 | + """Repeats what you type in.""" |
| 193 | + |
| 194 | + await ctx.channel.send(message) |
| 195 | + |
| 196 | +#dms |
| 197 | +@bot.command(pass_context = True) |
| 198 | +@commands.is_owner() |
| 199 | +async def setprefix(ctx, prefix): |
| 200 | + |
| 201 | + bot.command_prefix = prefix |
| 202 | + await ctx.send(f"Prefix changed to ``{prefix}``") |
| 203 | + await ctx.author.send("Alert! Prefix changed to ``{prefix}``!") |
| 204 | + |
| 205 | +#timer |
| 206 | +@bot.command() |
| 207 | +async def timer(ctx, time: int): |
| 208 | + """Timer(seconds) after the prefix(no.)-May be laggy.""" |
| 209 | + await ctx.send("Timer started") |
| 210 | + def check(message): |
| 211 | + return message.channel == ctx.channel and message.author == ctx.author and message.content.lower() == "cancel" |
| 212 | + try: |
| 213 | + m = await bot.wait_for("message", check=check, timeout=time) |
| 214 | + await ctx.send("Timer cancelled") |
| 215 | + except asyncio.TimeoutError: |
| 216 | + await ctx.channel.send('Timer is ringing {}!'.format(ctx.author.mention)) |
| 217 | + |
| 218 | +#nicknames |
| 219 | +@bot.command() |
| 220 | +@commands.has_permissions(administrator = True) |
| 221 | +async def nickname(ctx, m: discord.Member, *, newnick): |
| 222 | + """A nickname command for admins!""" |
| 223 | + await m.edit(nick=newnick) |
| 224 | + await ctx.send('Nickname changed.') |
| 225 | + |
| 226 | +#licence |
| 227 | +@bot.command(aliases=['terms']) |
| 228 | +async def licence(ctx): |
| 229 | + """Licence!""" |
| 230 | + embed = discord.Embed( |
| 231 | + title=('Info'), |
| 232 | + description =(f'This bot is distributed under the GPL 3.0 licence. Read the terms and conditions before using the code.'), |
| 233 | + |
| 234 | + color= discord.Colour.dark_blue() |
| 235 | + ) |
| 236 | + embed.set_footer(text='QWERTY') |
| 237 | + embed.set_thumbnail(url='') |
| 238 | + await ctx.send(embed=embed) |
| 239 | + |
| 240 | +#github |
| 241 | +@bot.command(aliases=['source']) |
| 242 | +async def github(ctx): |
| 243 | + """The GitHub page!""" |
| 244 | + await ctx.channel.send('https://github.com/QwertyIsCoding/QwertyBot') |
| 245 | + |
| 246 | +# When a member joins, the bot DM's them a message |
| 247 | +@client.event |
| 248 | +async def on_member_join(member): |
| 249 | + await client.send_message(member, 'Welcome to the server {}, Enjoy your stay! Also, Check out the rules and feel free to take prt in server events!'.format(member.name)) |
| 250 | + |
| 251 | + |
| 252 | + |
| 253 | +@bot.command(help = "Prints details of Server") |
| 254 | +async def details(ctx): |
| 255 | + owner=str(ctx.guild.owner) |
| 256 | + region = str(ctx.guild.region) |
| 257 | + guild_id = str(ctx.guild.id) |
| 258 | + memberCount = str(ctx.guild.member_count) |
| 259 | + icon = str(ctx.guild.icon_url) |
| 260 | + desc=ctx.guild.description |
| 261 | + |
| 262 | + embed = discord.Embed( |
| 263 | + title=ctx.guild.name + " Server Information", |
| 264 | + description=desc, |
| 265 | + color=discord.Color.blue() |
| 266 | + ) |
| 267 | + embed.set_thumbnail(url=icon) |
| 268 | + embed.add_field(name="Owner", value=owner, inline=True) |
| 269 | + embed.add_field(name="Server ID", value=guild_id, inline=True) |
| 270 | + embed.add_field(name="Region", value=region, inline=True) |
| 271 | + embed.add_field(name="Member Count", value=memberCount, inline=True) |
| 272 | + |
| 273 | + await ctx.send(embed=embed) |
| 274 | + |
| 275 | + members=[] |
| 276 | + async for member in ctx.guild.fetch_members(limit=150) : |
| 277 | + await ctx.send('Name : {}\t Status : {}\n Joined at {}'.format(member.display_name,str(member.status),str(member.joined_at))) |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | +#this is buggy |
| 282 | +@bot.event |
| 283 | +async def on_member_join(member): |
| 284 | + for channel in member.guild.text_channels : |
| 285 | + if str(channel) == "general" : |
| 286 | + on_mobile=False |
| 287 | + if member.is_on_mobile() == True : |
| 288 | + on_mobile = True |
| 289 | + await channel.send("Welcome to the Server {}!!\n On Mobile : {}".format(member.name,on_mobile)) |
| 290 | + |
| 291 | + |
| 292 | +#make a command to check user's roles |
| 293 | +#this is not working yet |
| 294 | +@bot.command() |
| 295 | +async def roles(ctx, member: discord.Member): |
| 296 | + """Check user's roles!""" |
| 297 | + roles = [role for role in member.roles] |
| 298 | + embed = discord.Embed( |
| 299 | + title=f"{member}'s roles", |
| 300 | + description="\n".join(roles), |
| 301 | + color=discord.Color.blue() |
| 302 | + ) |
| 303 | + await ctx.send(embed=embed) |
| 304 | + |
| 305 | +#make a command for a calculator in discord and round off the answer |
| 306 | +@bot.command() |
| 307 | +async def calc(ctx, *, equation): |
| 308 | + """Calculate anything!""" |
| 309 | + try: |
| 310 | + answer = eval(equation) |
| 311 | + except Exception: |
| 312 | + await ctx.send("Invalid equation!") |
| 313 | + return |
| 314 | + embed = discord.Embed( |
| 315 | + title="Calculator", |
| 316 | + description=f"{equation} = {answer}", |
| 317 | + color=discord.Color.blue() |
| 318 | + ) |
| 319 | + await ctx.send(embed=embed) |
| 320 | + |
| 321 | + |
| 322 | +#make a command to search for gifs |
| 323 | +@client.command(pass_context=True) |
| 324 | +async def giphy(ctx, *, search): |
| 325 | + embed = discord.Embed(colour=discord.Colour.blue()) |
| 326 | + session = aiohttp.ClientSession() |
| 327 | + |
| 328 | + if search == '': |
| 329 | + response = await session.get('https://api.giphy.com/v1/gifs/random?api_key=API_KEY_GOES_HERE') |
| 330 | + data = json.loads(await response.text()) |
| 331 | + embed.set_image(url=data['data']['images']['original']['url']) |
| 332 | + else: |
| 333 | + search.replace(' ', '+') |
| 334 | + response = await session.get('http://api.giphy.com/v1/gifs/search?q=' + search + '&api_key=API_KEY_GOES_HERE&limit=10') |
| 335 | + data = json.loads(await response.text()) |
| 336 | + gif_choice = random.randint(0, 9) |
| 337 | + embed.set_image(url=data['data'][gif_choice]['images']['original']['url']) |
| 338 | + |
| 339 | + await session.close() |
| 340 | + |
| 341 | + await client.send_message(embed=embed) |
| 342 | + |
| 343 | +#number guessing game |
| 344 | +@commands.command() |
| 345 | +async def guess(self, ctx): |
| 346 | + number = random.randint(0, 100) |
| 347 | + for i in range(0, 5): |
| 348 | + await ctx.send('guess') |
| 349 | + response = await self.bot.wait_for('message') |
| 350 | + guess = int(response.content) |
| 351 | + if guess > number: |
| 352 | + await ctx.send('bigger') |
| 353 | + elif guess < number: |
| 354 | + await ctx.send('smaller') |
| 355 | + else: |
| 356 | + await ctx.send('true') |
| 357 | + |
| 358 | +bot.run(TOKEN) |
| 359 | +client.run(TOKEN) |
0 commit comments