discord bots code example
Example 1: bot discord python
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!", description="The description")
@bot.event
async def on_ready():
print("Ready !")
@bot.command()
async def ping(ctx):
await ctx.send('**pong**')
bot.run("enter the token here between the quotes")
Example 2: discord.js bot
//first you must install dicord.js by running the command: npm install discord.js
//once u do that copy and paste this into your main file
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () =>{
client.user.setStatus('your status')
console.log('Connected!')
})
//rest of your code
//always remember to never share your token with anyone
client.login('your-token-here')
Example 3: how to import discord in python
py -3 -m pip install -U discord.py
Example 4: Discord.py bot example
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='prefix here')
@bot.event
async def on_ready():
print('Logged in as: ' + bot.user.name)
print('Ready!\n')
@bot.command()
async def commandname(ctx, *, somevariable)
Code goes here
await ctx.send('Message')
bot.run('yourtoken')
Example 5: discord bots
import discord
from discord.ext import commands
Token_1 = input("put your bot token here :")
Prefix_1 = input("put the prefix for your bot here :")
id_1 = input("put your bot id here :")
print("Link to invite --> https://discord.com/api/oauth2/authorize?client_id=785328945691885608&permissions=8&scope=bot")
client = commands.Bot(command_prefix = Prefix_1)
@client.event
async def on_ready():
print (f"Your bot is, Ready \n type {Prefix_1}hi in a server in which your bot is added ")
@client.command()
async def hi(ctx):
await ctx.send("hi This is a bot made by ALPHA")
embed=discord.Embed(title="[OP]", description="super OP bot", color=0x00ff00)
embed.add_field(name="hi !", value="hi This is a bot made by ALPHA", inline=False)
embed.add_field(name="Invite me !", value="To invite --> [click here](https://discord.com/api/oauth2/authorize?client_id=785328945691885608&permissions=8&scope=bot)", inline=False)
await ctx.send(embed=embed)
client.run(Token_1)
Example 6: how to make a discord bot
//discord.js is probably the easiest to learn. To install do this
//in command prompt (Windows, Linux) or terminal (Mac)
npm init
//and then
npm i discord.js
//after that just read the discord.js.org documentation
//and follow a couple yt guides, maybe join some servers.