Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

discord py bot example

import discord

token = ''

# Simple Echo Bot

class MyClient(discord.client):

	async def on_ready(self):
    	print(f'Logged on as {self.user}!')
    
    async def on_message(self, message):
    	if message.author == self.user: return
        await message.reply(message.content)

# Need to enable intents in bot settings
intents = discord.Intents().all()
client = MyClient(intents=intents)

client.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

PREVIOUS NEXT
Code Example
Python :: convert numpy array to tensor 
Python :: print list in reverse order python 
Python :: pd df drop columns 
Python :: python sorted dictionary multiple keys 
Python :: sort a series pandas 
Python :: check tensor type tensorflow 
Python :: how to load wav file with python 
Python :: continual vs continuous 
Python :: difference between generator and iterator in python 
Python :: python loop list from last to first 
Python :: python sorted word frequency count 
Python :: where is tensorflow slim 
Python :: resto division python 
Python :: Python Tkinter SpinBox Widget 
Python :: how to check if any item in list is in anoter list 
Python :: sort dict by values 
Python :: how to take input complex number in python 
Python :: pyautogui press 
Python :: compress tarfile python 
Python :: remove unnamed 0 column pandas 
Python :: list python virtual environments 
Python :: isnumeric 
Python :: pandas merge on index column 
Python :: how to clean environment python 
Python :: palindrome string python 
Python :: python column multiply 
Python :: boto3 delete bucket object 
Python :: python get file path 
Python :: matplotlib position legend 
Python :: last executed query in flask api 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =