Rules and Common Practices | Pycord Guide (2024)

When creating almost anything, there's always a certain set of rules to follow or common practices,such as PEP8 for Python. This applies to creating botswith Pycord as well.

note

Most of these rules and common practices are only applicable forverified bots,but it's good to follow them nonetheless.

There are rules for creating bots, and most of these are required by Discord themselves, not us atPycord. Not following these rules may get your bot denied for verification.

Terms of Service and Privacy Policy

Starting at some point in time, Discord has made providing a privacy policy with your bot a requirement.This is so that Discord knows exactly what you are doing with its users' data.

tip

You don't need a lawyer or anyone special to write out a privacy policy for you, nor do you needit approved by some official entity. Simply writing out how you are going to use Discord userinformation neatly is all you need to do.

Providing a Terms of Service for your bot is optional, though usually a best practice. It tells userswhat they can and cannot do with your service, and makes it easier to settle disputes if someonedisagrees with you.

Read more in Discord's official Legal Docs.

Developer Policy

We could list almost every rule about using Discord's API here. Or we could simply link Discord'sDeveloper Policy to make it easier on us. You can find Discord's Developer Policyhere. This outlines what you can and cannot do withDiscord's Developer API. And, don't worry, it's completely readable and understandable.

Best Practices

Now, here's something we can't simply link an article for. We're going to discuss the best practicesof creating a Discord bot with Pycord.

Bot Sharding

To any new or maybe even experienced bot developer, sharding a bot sounds beneficial once you hearabout it. I'm here to tell you that it isn't a good idea to shard your bot.

Wait a minute, why would it be an option if it wasn't a good idea? It's simple. I lied. Sort of.I'm not going to go into the details of sharding a bot, so you can read about it onthis page. Sharding is the process of taking your botand breaking it up into small pieces, so it's easier to perform tasks. This is very useful for largebots, as it makes them faster and more reliable. Sharding is not a good practice for small bots.

note

Discord will notify you once it is time to shard your bot, and will eventually force you to do so.

At the very least, wait for one thousand servers to shard your bot. If you shard your bot while it'ssmall, you'll just be wasting resources and possibly making your bot slower.

Verification

Verifying your Discord bot is something every developer would like to achieve. It shows that your botis in more than 75 servers. It's generally a good idea to try to get your bot verified as soon aspossible. We're talking at 76 servers soon. This is because Discord can be somewhat slow in terms ofbot verification, so verifying as soon as possible gives them enough time to verify before your botreaches the 100 server cap. If a bot is not verified, it cannot grow beyond 100 servers.

It's also a good idea to only apply for the privileged intents that you need. Applying for intentsyour bot doesn't use wastes both your time and Discord's time, as your privileged intent requestwill be denied simply because you applied for an intent you didn't need.

Subclassing

While it may take some time, subclassing a bot is very worth it. Once again, this was explainedelsewhere, so I won't go into the details, but I felt it fit here, so I put it here.

Subclassing a bot makes it more flexible and allows it to do a lot more. Read more about subclassingbots here

Your Bot's Token

Your bot is only able to be run for one reason: its token. If you followed theguide for creating your first bot, you should already know a bit aboutkeeping that token safe. That's exactly what you want to do.

Sharing your token is never good. If someone evil gets a hold of your token, they can do terrible things,such as making your bot leave all of its servers, spamming all the members the bot has contact with,and even manipulating the servers the bot is in, if given the permissions. That's why it's very importantto keep your token safe. To learn how to do so, read this part ofthe Creating Your First Bot guide.

Backups

You always want to back up your bot's data. This includes both its code and its databases. This way,if something tragic happens, such as your host failing a data migration or you breaking your RaspberryPi's SD card that held your bot, you'll still have its precious user data. I have a small program formy bot that uploads its databases to a remote GitHub repository periodically to not lose any data.It may be smarter to find a bit more of a reliable way to do so, though.

Public or private, having a local Git repository connected to a remote one is a good idea for makingalmost any application. For a lot of developers, it's like saving your work. If you do this, all ofyour bot's code won't be lost if your computer spontaneously combusts, or you smash it to bits fromanger. You can simply grab the backup computer that everyone has lying around, and you're backin business.

Organization and Cleanliness

It is extremely important to have organized code. This includes commands, objects, functions,and classes. If you don't have organized code, it will get progressively harder for you to recognizeit, and others won't be able to decipher it.

Make sure you utilize indents and spaces, as these are very important in making your code readable.

Bad Spacing

class MyClass:
async def add(self,num1,num2):
return num1+num2
async def sub(self,num1,num2):
return num1-num2

Good Spacing

class MyClass:
async def add(self, num1, num2):
return num1 + num2

async def sub(self, num1, num2):
return num1 - num2

See the difference? Now, which one looks more readable? Hopefully, you answered the second example.Python's PEP8 is a PEP (Python Enhancement Proposal)style guide for Python. It is the style guide that is used by most Python developers and programmers,providing a universal way to write and read code.

Databases

As your bot grows, you'll inevitably have to store data for your bot. Now, most people would probably just load up someJSON file on boot into a dict, modify it in memory then write to the file. However, JSON files aren't the solution.When you write to a JSON file, it rewrites the entire file instead of just rewriting the section that changed. It's alsoa configuration file format, not a storage file format.

Instead of using a JSON file or some other related format, you should instead use a database. There are many databasesout there, like MongoDB, SQLite, and PostgreSQL to name a few.

All of these databases I named do the job well, and which one you use depends on what features you want out of a database.

MongoDB

MongoDB is a JSON-like format and if you already use JSON files, it shouldn't be too hard to migrate over to.

SQLite

SQLite is based on SQL, a common relational data model. It's a lightweight, easy-to-use, portable database solution thatworks entirely on files. However, if for some reason you cannot read/write to and from a file, and you need to managelots of data, SQLite might not be for you.

While SQLite is a part of the Python Standard Library as the sqlite3 package, we recommend not using it as it issynchronous and blocking. You should use an asynchronous alternative, such as aiosqlite.

PostgreSQL

PostgreSQL is also based on SQL, but it also has more features than SQLite. It's compliant with the SQL standard,open-source, and extensible. However, it's not that fast or simple compared to SQLite.

MariaDB

MariaDB is also based on SQL and is a fork of the MySQL project. It's compliant with the SQL standard, it's also opensource and is a complete drop-in replacement for any code with MySQL. You don't even need to change what package you'reusing!

Rules and Common Practices | Pycord Guide (2024)

FAQs

Rules and Common Practices | Pycord Guide? ›

There comes a point in your bot's development when you want to organize a collection of commands, listeners, and some state into one class. Cogs allow you to do just that. The gist: Each cog is a Python class that subclasses commands.

What are cogs in Discord? ›

There comes a point in your bot's development when you want to organize a collection of commands, listeners, and some state into one class. Cogs allow you to do just that. The gist: Each cog is a Python class that subclasses commands.

How to setup pycord? ›

To install Pycord, you can use the following command in your terminal:
  1. pip install py-cord.
  2. pip install "py-cord[voice]"
  3. pip install -U py-cord.
  4. pip uninstall discord. py.
  5. pip install py-cord.
Aug 20, 2024

What are Discord intents? ›

Intents are bitwise values that can be ORed ( | ) to indicate which events (or groups of events) you want Discord to send your app. A list of intents and their corresponding events are listed in the intents section.

What is sharding in Discord? ›

Sharding is a method to split portions of bots into separate processes. This is an enforced strategy by Discord once a bot reaches a certain number of guilds (2500). Once this number is reached, a bot must be sharded in a way that only 2500 guilds maximum may be allocated per shard.

What is VC in Discord? ›

Discord -- Voice chat

This will allow you to speak with anyone else in the same channel.

What is pancake in Discord? ›

Pancake is a high quality, multipurpose bot for your Discord server.

What are the 4 numbers in Discord? ›

The 4 digits after one's username are very useful in finding and adding your friends. A few other platforms and some video games use similar systems which make is WAY easier to find the people you want to find. The times of (random example, no specific user) xXShadowBeast347892Xx are over.

What is the secret thing in Discord? ›

Click the Discord logo 16 times.

This is only available on Discord's web and desktop app, and clicking the logo 16 times will play the "Discordo" audio. Close Discord and open it again to hear the "Discordo" audio again. Once you've turned it on, you'll hear the "Discordo" audio whenever you open the desktop app.

Are Discord warnings real? ›

Discord will continue to send warnings to users that inform them of our rules. We may send warnings when a user was in a server that broke our rules or if they interacted with content that broke our rules, but did not engage in the violating behavior themselves.

What are server shards? ›

A single machine, or database server, can store and process only a limited amount of data. Database sharding overcomes this limitation by splitting data into smaller chunks, called shards, and storing them across several database servers.

What is a shard ID? ›

ShardId. The unique identifier of the shard within the stream. Type: String. Length Constraints: Minimum length of 1. Maximum length of 128.

What is a server vanity Discord? ›

A vanity URL is a custom URL that replaces the generic one provided by Discord when you first create a server. This custom URL can be used to access your server and make it easier for others to find and join.

What is the cog icon on Discord? ›

cog icon to open your User Settings. On desktop, you'll find it in the lower left corner of your server. From User Settings, head to Voice and Video settings to adjust your audio input, input sensitivity, and more.

What are cogs in code? ›

Cogs, often known as modules or extensions, are used to organize commands into groups. This is useful for grouping commands that have the same general idea (such as moderation commands). This also helps to avoid making your bot's files messy and cluttered.

Where is the cogwheel on Discord? ›

1. Tap on your avatar in the bottom right corner to pull up your User Settings. 2. Next, tap on the cogwheel [ ] at the top right corner.

What is a cog in programming? ›

Cog is a simple code generation tool written in Python. We use it or its results every day in the production of Kubi. Kubi is a collaboration system embodied in a handful of different products.

Top Articles
Securing Internet Connection: All about the SSL Port or Secured Ports
Set up Multipoint headphones on your devices
Funny Roblox Id Codes 2023
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Joi Databas
DPhil Research - List of thesis titles
Shs Games 1V1 Lol
Evil Dead Rise Showtimes Near Massena Movieplex
Steamy Afternoon With Handsome Fernando
Which aspects are important in sales |#1 Prospection
Detroit Lions 50 50
18443168434
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Grace Caroline Deepfake
978-0137606801
Nwi Arrests Lake County
Immortal Ink Waxahachie
Craigslist Free Stuff Santa Cruz
Mflwer
Spergo Net Worth 2022
Costco Gas Foster City
Obsidian Guard's Cutlass
Marvon McCray Update: Did He Pass Away Or Is He Still Alive?
Mccain Agportal
Amih Stocktwits
Fort Mccoy Fire Map
Uta Kinesiology Advising
Kcwi Tv Schedule
What Time Does Walmart Auto Center Open
Nesb Routing Number
Random Bibleizer
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Black Lion Backpack And Glider Voucher
Gopher Carts Pensacola Beach
Duke University Transcript Request
Lincoln Financial Field, section 110, row 4, home of Philadelphia Eagles, Temple Owls, page 1
Jambus - Definition, Beispiele, Merkmale, Wirkung
Netherforged Lavaproof Boots
Ark Unlock All Skins Command
Craigslist Red Wing Mn
D3 Boards
Jail View Sumter
Nancy Pazelt Obituary
Birmingham City Schools Clever Login
Thotsbook Com
Vérificateur De Billet Loto-Québec
Funkin' on the Heights
Vci Classified Paducah
Www Pig11 Net
Ty Glass Sentenced
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 5807

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.