-
Notifications
You must be signed in to change notification settings - Fork 20
Getting Started
This page here gives a brief introduction into the selfcord library.
To install selfcord run this in the command line.
pip install selfcord.py
Let's try to make a selfbot that responds to a message ("ping!") with another message ("pong"). First create a file named example.py
and write this inside of it.
import selfcord
token = "insert token"
bot = selfcord.Bot()
@bot.on("ready")
async def ready(time):
print(f"Connected To {bot.user.name}\n Startup took {time:0.2f} seconds")
@bot.on("message")
async def responder(message):
if message.content == "ping!":
await message.channel.send("pong!")
bot.run(token)
To explain this, we first import the selfcord library. Next we define the token where it states "insert token". This is our user token and must be protected at all costs, for the sake of examples I did this for simplicity, however please use environment variables for this.
Next we initialise the bot instance, this is essentially our connection to discord gateway and discord api.
We use the @bot.on
decorator to define events. There are many events in selfcord, the READY event is fired when the client begins its connection.
We use the same decorator again but for the MESSAGE_CREATE event. This is fired when a message is created and it returns a message object, we can check the content attribute for this message and check if it is equal to ping!. If so, the bot will reply with pong!.
To run this one must run in the command line.
python example.py
In this example, we are going to make a bot that responds to !pong
with ping!
with the cmd
decorator. This decorator is used to easily add commands.
import selfcord
token = "insert token"
bot = selfcord.Bot(prefixes=["!", ">"])
@bot.on("ready")
async def ready(time):
print(f"Connected To {bot.user.name}\n Startup took {time:0.2f} seconds")
@bot.cmd()
async def ping(ctx):
await ctx.reply("pong!")
bot.run(token)
Similar to the last example, we import the library, define our token and initialise the bot class. We also define two prefixes used for our bot.
So whenever the user types !ping or >ping in chat, they are responded with pong!.
To run this one must run in the command line.
python example.py
Our discord server: https://discord.gg/M43gDaHsry
yey