├── README.md ├── main.py ├── media ├── 107.jpg ├── 108.jpg ├── 110.jpg ├── 111.jpg ├── 112.jpg ├── 113.jpg ├── 114.jpg ├── 115.jpg ├── 116.jpg ├── image-123.jpg └── image-124.jpg └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # Python-Discord-Bot-Template 2 | 3 | This repository is a Python Discord bot template that anyone can use to start building their own Discord bot. It is specially designed for beginner programmers who are just starting to learn how to work with `discord.py.` Please keep in mind that while this template may not be the absolute best one available, it is still a great starting point for learning how Discord bots work and for creating your own bot with ease. 4 | 5 | ## Index 6 | * [💪- Support](#--support) 7 | * [🎫-Get the Discord Token](#-get-the-discord-token) 8 | * [✉️-Invite Your Bot to Join a Server](#%EF%B8%8F-invite-your-bot-to-join-a-server) 9 | * [📩-How to download it](#-how-to-download-it) 10 | * [🚦-How to start](#-how-to-start) 11 | * [👩‍💻-Code in detail](#-code-in-detail) 12 | * [📖-Library Used](#-library-used) 13 | 14 | ## 💪- Support 15 | 16 | - Please ensure that you keep the credits and a link to this repository in all files containing my code. This will help me as a developer, and new programmers can access the link to get some additional help if needed 17 | - If you are unfamiliar with the basics of discord.py, [here](https://www.pythondiscord.com/resources) is a link to some resources that can help you learn. 18 | 19 | ## 🎫-Get the Discord Token 20 | 21 | Here are the step to creating a Discord Bot account: 22 | - Make sure you’re logged on to the [Discord website.](https://discord.com/) 23 | - Navigate to the [application page.](https://discord.com/developers/applications) 24 | - Click on the “New Application” button. 25 | 26 | 27 | 28 | 29 | - Give the application a name and click “Create”. 30 | 31 | 32 | 33 | - Go to the “Bot” tab and click “Add Bot”. Confirm by clicking "Yes, do it!" 34 | 35 | 36 | 37 | **Keep the default settings for Public Bot (checked) and Require **OAuth2 Code Grant**(unchecked).** 38 | - `Your bot has been created.` 39 | 40 | 41 | 42 | - Copy the token. Remember, this token is your bot's password, so don't share it with anyone. Sharing it could allow someone to log in to your bot and perform malicious actions. If the token accidentally gets shared, you can regenerate it. 43 | 44 | ## ✉️-Invite Your Bot to Join a Server 45 | 46 | Now you have to get your Bot User into a server. To do this, you should create an invite URL for it. 47 | - Go to the "OAuth2" tab. Then select "bot" under the "scopes" section. 48 | 49 | 50 | 51 | - Now choose the permissions you want for the bot. Our bot is going to mainly use text messages so we don't need a lot of the permissions. You may need more depending on what you want your bot to do. Be careful with the "Administrator" permission. 52 | 53 | 54 | 55 | - After selecting the appropriate permissions, click the 'copy' button above the permissions. That will copy a URL which can be used to add the bot to a server.Paste the URL into your browser, choose a server to invite the bot to, and click “Authorize”. 56 | - Now that you've created the bot user, we'll start writing the Python code for the bot. 57 | 58 | ## 📩-How to download it 59 | 60 | - Clone/Download the repository by typing the following command in your terminal (Linux, Mac & Windows), or your Command Prompt ( Windows) . 61 | - `if u get an error like: 'git' is not recognized as an internal or external command, u need to download Git.` 62 | - [For more help visit](https://stackoverflow.com/questions/4492979/git-is-not-recognized-as-an-internal-or-external-command) 63 | 64 | ``` 65 | git clone https://github.com/MrAdityaBhoyar/Python-Discord-Bot-Template.git 66 | ``` 67 | - Or just download the repo 68 | 69 | ## 🚦-How to start 70 | - Before getting started u need to download the library `discord.py`, by typing the following command in your terminal (Linux, Mac & Windows), or your Command Prompt ( Windows) . 71 | 72 | ``` 73 | pip install -r requirements.txt 74 | ``` 75 | - Now fill the important information in [main.py](https://github.com/MrAdityaBhoyar/Python-Discord-Bot-Template/blob/main/main.py) 76 | 77 | | Variable | What it is | 78 | | ------------------------- | ----------------------------------------------------------------------| 79 | | YOUR_BOT_PREFIX_HERE | The prefix you want to use for normal commands | 80 | | YOUR_BOT_TOKEN_HERE | The token of your bot | 81 | 82 | 83 | ## 👩‍💻-Code in detail 84 | 85 | About the code in detail 86 | ### on_ready 87 | ``` 88 | @client.event 89 | async def on_ready(): 90 | print("We have logged in as {0.user} ".format(client)) 91 | activity = discord.Game(name=".help", type=3) 92 | await client.change_presence(status=discord.Status.online, activity=activity) 93 | ``` 94 | This command will print we have logged in as botname, and this is for making the status as an online and writing prefix in playing a game 95 | 96 | 97 | 98 | ### Help Command 99 | ``` 100 | @client.group(invoke_without_command=True) 101 | async def help(ctx): 102 | embed = discord.Embed(title="IndianDesiMemer Help Center ✨",color=0xF49726) 103 | embed.add_field(name="Command Categories :",value="🐸 `memes :` Image generation with a memey twist.\n" + "🔧 `utility :` Bot utility zone\n😏 `nsfw :` Image generation with a memey twist.\n\nTo view the commands of a category, send `.help `" ,inline=False) 104 | embed.set_footer(icon_url=ctx.author.avatar_url,text="Help requested by: {}".format(ctx.author.display_name)) 105 | await ctx.send(embed=embed) 106 | ``` 107 | this command will print the help command and you can customise it as your need 108 | 109 | 110 | 111 | ### Sub-help command 112 | 113 | ``` 114 | #Sub-help command of memes 115 | @help.command () 116 | async def memes(ctx): 117 | embed=discord.Embed(title="IndianDesiMemer Help Center ✨", description="Commands of **meme** \n`.meme:`Memes",inline=False) 118 | embed.set_footer(icon_url=ctx.author.avatar_url,text="Command requested by: {}".format(ctx.author.display_name)) 119 | await ctx.send(embed=embed) 120 | 121 | 122 | #Sub-help commands of nsfw 123 | @help.command () 124 | async def nsfw(ctx) : 125 | embed=discord.Embed(title="IndianDesiMemer Help Center ✨", description="Commands of **nsfw** \n`.nsfw:`NSFW", color=0xF49726) 126 | embed.set_footer(icon_url=ctx.author.avatar_url,text="Command requested by: {}".format(ctx.author.display_name)) 127 | await ctx.send(embed=embed) 128 | 129 | 130 | #Sub-help commands of utility 131 | @help.command () 132 | async def utility(ctx) : 133 | embed=discord.Embed(title="IndianDesiMemer Help Center ✨", description="Commands of **utility** \n`.ping:`Latency", color=0xF49726) 134 | embed.set_footer(icon_url=ctx.author.avatar_url,text="Command requested by: {}".format(ctx.author.display_name)) 135 | await ctx.send(embed=embed) 136 | ``` 137 | 138 | Like: 139 | 140 | 141 | 142 | ### Cooldown 143 | 144 | ``` 145 | @client.event 146 | async def on_command_error(ctx, error): 147 | if isinstance(error, commands.CommandOnCooldown): 148 | await ctx.send("**Try after {0} second ".format(round(error.retry_after, 2))) 149 | 150 | @client.command() 151 | @commands.cooldown(1, 10, commands.BucketType.channel) # 1 Command every 10 sec 152 | async def meme(ctx): 153 | await ctx.send("Memes") 154 | ``` 155 | Cooldown is used to prevent the bot from spam attack,its basically in your own need 156 | 157 | 158 | 159 | ### NSFW 160 | 161 | ``` 162 | @client.command() 163 | @commands.cooldown(1, 10, commands.BucketType.channel) 164 | async def nsfw(ctx): 165 | if ctx.channel.is_nsfw(): 166 | print("nsfw work!!") 167 | else: 168 | print("You can use this command in a nsfw channel only !") 169 | ``` 170 | Many bot creators may want to add an NSFW command to their bots, but it is crucial to ensure that users are protected and that the content expires safely. To achieve this, the command should only be executed in an age-restricted channel. 171 | 172 | 173 | 174 | ## 📖-Library Used 175 | - [discord.py](https://pypi.org/project/discord.py/) 176 | - [requests](https://pypi.org/project/requests/) 177 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import discord 2 | from discord.ext import commands 3 | import requests 4 | 5 | token = YOUR_BOT_PREFIX_HERE 6 | prefix = YOUR_BOT_TOKEN_HERE 7 | 8 | client = commands.Bot(command_prefix= prefix) 9 | client.remove_command("help") #to remove the default boring help command 10 | 11 | 12 | @client.event 13 | async def on_ready(): 14 | print("We have logged in as {0.user} ".format(client)) 15 | activity = discord.Game(name=".help", type=3) # this is to writing prefix in playing a game.(optional) 16 | await client.change_presence(status=discord.Status.online, activity=activity) # this is for making the status as an online and writing prefix in playing a game.(optional) 17 | 18 | 19 | 20 | 21 | #Help commands 22 | @client.group(invoke_without_command=True) 23 | async def help(ctx): 24 | embed = discord.Embed(title="IndianDesiMemer Help Center ✨",color=0xF49726) 25 | embed.add_field(name="Command Categories :",value="🐸 `memes :` Image generation with a memey twist.\n" + "🔧 `utility :` Bot utility zone\n😏 `nsfw :` Image generation with a memey twist.\n\nTo view the commands of a category, send `.help `" ,inline=False) 26 | embed.set_footer(icon_url=ctx.author.avatar_url,text="Help requested by: {}".format(ctx.author.display_name)) 27 | await ctx.send(embed=embed) 28 | 29 | 30 | #Sub-help command of memes 31 | @help.command () 32 | async def memes(ctx): 33 | embed=discord.Embed(title="IndianDesiMemer Help Center ✨", description="Commands of **meme** \n`.meme:`Memes",inline=False) 34 | embed.set_footer(icon_url=ctx.author.avatar_url,text="Command requested by: {}".format(ctx.author.display_name)) 35 | await ctx.send(embed=embed) 36 | 37 | 38 | #Sub-help commands of nsfw 39 | @help.command () 40 | async def nsfw(ctx) : 41 | embed=discord.Embed(title="IndianDesiMemer Help Center ✨", description="Commands of **nsfw** \n`.nsfw:`NSFW", color=0xF49726) 42 | embed.set_footer(icon_url=ctx.author.avatar_url,text="Command requested by: {}".format(ctx.author.display_name)) 43 | await ctx.send(embed=embed) 44 | 45 | 46 | #Sub-help commands of utility 47 | @help.command () 48 | async def utility(ctx) : 49 | embed=discord.Embed(title="IndianDesiMemer Help Center ✨", description="Commands of **utility** \n`.ping:`Latency", color=0xF49726) 50 | embed.set_footer(icon_url=ctx.author.avatar_url,text="Command requested by: {}".format(ctx.author.display_name)) 51 | await ctx.send(embed=embed) 52 | 53 | 54 | # it is used for the cooldown to prevent the bot from spam attack 55 | @client.event 56 | async def on_command_error(ctx, error): 57 | if isinstance(error, commands.CommandOnCooldown): 58 | await ctx.send("**Try after {0} second ".format(round(error.retry_after, 2))) 59 | 60 | 61 | #meme command 62 | @client.command() 63 | @commands.cooldown(1, 10, commands.BucketType.channel) # it is used for the cooldown to prevent the bot from spam attack 64 | async def meme(ctx): 65 | 66 | response = requests.get("https://meme-api.herokuapp.com/gimme/"+"memes"+"memes"+"?t=all?hot") 67 | 68 | m = response.json() 69 | postLink = (m["postLink"]) 70 | subreddit = (m["subreddit"]) 71 | title = (m["title"]) 72 | imageUrl = (m["url"]) 73 | upVote = (m["ups"]) 74 | uv = str(upVote) 75 | 76 | embed=discord.Embed(title= title, url=postLink,color=0xF49726) 77 | embed.set_image(url=imageUrl) 78 | embed.set_footer(text="\n👍\t"+ uv+ " By :r/"+subreddit) 79 | await ctx.send(embed=embed) 80 | 81 | #nsfw command 82 | @client.command() 83 | @commands.cooldown(1, 10, commands.BucketType.channel) 84 | async def nsfw(ctx): 85 | if ctx.channel.is_nsfw(): 86 | print("nsfw work!!") 87 | else: 88 | print("You can use this command in a nsfw channel only !") 89 | 90 | 91 | #ping command 92 | @client.command() 93 | @commands.cooldown(1, 10, commands.BucketType.channel) # it is used for the cooldown to prevent the bot from spam attack 94 | async def ping(ctx): 95 | await ctx.send('Ping! **{0}**ms'.format(round(client.latency, 1))) 96 | 97 | 98 | client.run(token) 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /media/107.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/107.jpg -------------------------------------------------------------------------------- /media/108.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/108.jpg -------------------------------------------------------------------------------- /media/110.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/110.jpg -------------------------------------------------------------------------------- /media/111.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/111.jpg -------------------------------------------------------------------------------- /media/112.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/112.jpg -------------------------------------------------------------------------------- /media/113.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/113.jpg -------------------------------------------------------------------------------- /media/114.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/114.jpg -------------------------------------------------------------------------------- /media/115.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/115.jpg -------------------------------------------------------------------------------- /media/116.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/116.jpg -------------------------------------------------------------------------------- /media/image-123.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/image-123.jpg -------------------------------------------------------------------------------- /media/image-124.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aadityabhoyarr/python-discord-bot-template/d4f53525bd4b1589fb6369d3cf824d2b204b9f48/media/image-124.jpg -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | discord.py 2 | requests 3 | --------------------------------------------------------------------------------