Answers for "how to be a discord bot"

10

how to make a discord bot

#________________________________________________________________________________________#
#                                                                                        #
#                               How to make a discord bot                                #
#________________________________________________________________________________________#


# BE AWARE! YOU NEED TO CUSTOMIZE/CONFIGURE THIS CODE OTHERWISE IT WON'T WORK. 
# THIS CODE IS JUST THE BASICS



# IMPORT DISCORD.PY. ALLOWS ACCESS TO DISCORD'S API.
import discord

# IMPORTS EXTENSIONS FOR COMMANDS
from discord.ext import commands


# IMPORT THE OS MODULE.
import os

# IMPORT LOAD_DOTENV FUNCTION FROM DOTENV MODULE.
from dotenv import load_dotenv

# IMPORT LOGGING

import logging


# LOADS THE .ENV FILE THAT RESIDES ON THE SAME LEVEL AS THE SCRIPT.
load_dotenv()

# GRAB THE API TOKEN FROM THE .ENV FILE.
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")

# GETS THE CLIENT OBJECT FROM DISCORD.PY. CLIENT IS SYNONYMOUS WITH BOT.
bot = discord.Client()

logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)


bot = commands.Bot(command_prefix='Yourprefix')

# UNDER THIS LINE OF CODE ARE THE COMMANDS FOR THE BOT. YOU CAN ADD/CHANGE THOSE SAFELY WITHOUT DESTORYING THE CODE

@bot.command()
async def test(ctx, *, arg):
	await ctx.send(arg, file=discord.File('yourfile.png'))


@bot.command()
async def laugh(ctx):
	await ctx.send("typeherealink")




@bot.command()
async def die(ctx):
	exit()



# EXECUTES THE BOT WITH THE SPECIFIED TOKEN. DON'T REMOVE THIS LINE OF CODE JUST CHANGE THE "DISCORD_TOKEN" PART TO YOUR DISCORD BOT TOKEN
bot.run(DISCORD_TOKEN)

#________________________________________________________________________________________#

# If this code helped you please leave a like on it. If you want to see more of this follow me
# Or just take a look at another answer of my answers
#
# THIS CODE HAS BEEN MADE BY : Vast Vicuña
Posted by: Guest on September-04-2021
6

discord bots

#go to -- https://python.org 
#Download and install python
#go to CMD and install -- pip install discord
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(): #Bot on
    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)
Posted by: Guest on May-24-2021
0

what are discord bots

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '!')

@client.event
async def on_ready():
	print('Bot is Connected!')
    
@client.command() # An example message command
async def ping(ctx):
  await ctx.send('Pong!')
  
@client.command() # An example timer
async def timer(ctx, timeSecond):
  try:
    timeSeconds = int(timeSecond)
    timer_msg = await ctx.send(f'**{timeSeconds}** seconds remaining!')
	while timeSecond != 0:
      timeSeconds -= 1
      timer_msg.edit(content=f'**{timeSeconds}** seconds remaining!')
    await ctx.send(f'{ctx.author.mention} **TIMER ENDED!!!**')
  except ValueError:
    await ctx.send('Sorry, it must be a number!')
  
client.run('TOKEN') # <--------- Your Discord bot Token Here
Posted by: Guest on May-12-2021
-2

how to make a discord bot

mkdir musicbot && cd musicbot
Posted by: Guest on July-01-2020

Python Answers by Framework

Browse Popular Code Answers by Language