Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make a discord bot in python

import discord
from discord.ext import commands

client = commands.Bot(command_prefix=".")

@client.event
async def on_ready():
    print("Ready!")

bot.run("TOKEN")
Comment

python discord bot

import discord
from discord.ext import commands
bot = commands.Bot("!")
@bot.command()
async def test(ctx):
   print('hello')
bot.run('token')
Comment

discord bot python example

from multiprocessing.connection import Client
from urllib import response
import discord
import random
import os






TOKEN = 'YOUR TOKEN'

client = discord.Client()

@client.event
async def on_ready():
    print('I have logged in as {0.user} '.format(client))


    

@client.event
async def on_message(message):
    username = str(message.author).split('#')[0]
    user_message = str(message.content)
    channel = str(message.channel.name)
    print(f'{username}: {user_message} ({channel})')
    

    if message.author == client.user:
        return
    
    if message.channel.name == 'YOUR CHANNEL':
        if user_message.lower() == 'hello':
            await message.channel.send(f'Hello {username}!')
            return 
        elif user_message.lower() == 'bye':
            await message.channel.send(f'See you later {username}.')
            return 
        
    
    if message.channel.name == 'YOUR CHANNEL':
        if user_message.lower() == '.random':
            response = f'This is your random number: {random.randrange(1000000000)}'
            await message.channel.send(response)
            return
        elif user_message.lower() == '.help':
            response = f'This is a list of all availabe commands: 1. .random (Displays you a random number) 2. .help (Displays you a list with all avaiable commands)'
            await message.channel.send(response)
            return
        elif user_message.lower() == '.ping':
            response = f'**Pong**'
            await message.channel.send(response)
            return
        




client.run(TOKEN)
Comment

Python basic discord bot

from cmath import log
from tracemalloc import start
import discord
from discord.ext import commands
from requests import request
import os
from random import seed
from random import randint


intents = discord.Intents().all();
client = commands.Bot(command_prefix="!"); // set the command prefix for the bot
game = discord.Game(name="YOUR-ACTIVITY"); // set the bot actual activity

@client.event
async def on_ready():
    await client.change_presence(activity=game); // Set the activity of the bot when ready
    print("The bot is ready!") // Send a msg in your terminal to say that the bot is ready

@client.command()
@commands.is_owner()
async def shutdown(context): // Shutdown the bot (Only used by the bot owner) -> Respond to !shutdown command
    exit()

@client.command()
async def hello(ctx): // Send "Hi" message to the channel (Usable by anyone) -> Respond to !hello command   
    await ctx.send("Hi")

@client.event
async def on_message(message):
    if (message.content.startswith("!") == False and message.author != client.user and (message.channel.name == "bot")): // Juste a double check that the bot isn't responding to himself, that the msg is not a command and that the bot only respond in  "bot" channel
    if message.content.startswith("!") == True: // If the message is a command
        await client.process_commands(message) // Process the command

token = "YOUR-TOKEN"
client.run(token)
  
Comment

discord python application bot

q_list = [
    'What is your favorite color?',
    'Is the Sky Blue?',
    'Am I the best bot ever?'
]

a_list = []


@client.command(aliases=['staff-application'])
async def staff_application(ctx):
    a_list = []
    submit_channel = client.get_channel(<your channel id>)
    channel = await ctx.author.create_dm()

    def check(m):
        return m.content is not None and m.channel == channel

    for question in q_list:
        sleep(.5)
        await channel.send(question)
        msg = await client.wait_for('message', check=check)
        a_list.append(msg.content)

    submit_wait = True
    while submit_wait:
        await channel.send('End of questions - "submit" to finish')
        msg = await client.wait_for('message', check=check)
        if "submit" in msg.content.lower():
            submit_wait = False
            answers = "
".join(f'{a}. {b}' for a, b in enumerate(a_list, 1))
            submit_msg = f'Application from {msg.author} 
The answers are:
{answers}'
            await submit_channel.send(submit_msg)
Comment

discord bot python

from nextcord.ext import commands

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

@bot.command()
async def test(ctx):
    pass

# or:

@commands.command()
async def test(ctx):
    pass

bot.add_command(test)
Comment

PREVIOUS NEXT
Code Example
Python :: docker compose cron 
Python :: continue statement in python 
Python :: num2words python 
Python :: Returns the first row as a Row 
Python :: convert exception to string python 
Python :: atoi in python code 
Python :: api testing python 
Python :: pandas get row if difference previous 
Python :: loops in python 
Python :: how to check if digit in int python 
Python :: Create a hexadecimal colour based on a string with python 
Python :: determinant of 3x3 numpy 
Python :: loading bar in python 
Python :: pandas weighted average groupby 
Python :: python check if number contains digit 
Python :: python interview questions and answers pdf 
Python :: numpy add 
Python :: python built in libraries 
Python :: python ignore first value in generator 
Python :: how to store categorical variables in separate dataframe 
Python :: set intersection 
Python :: list add pythhon 
Python :: django password hashers 
Python :: @ in python 
Python :: run python on android 
Python :: np.transpose(x) array([[0, 2], [1, 3]]) 
Python :: service 
Python :: how to make python faster than c++ 
Python :: custom permission class django rest framework 
Python :: create and add many to many field in django 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =