0
Q:

How to setup discord.py bot

import discord

class MyClient(discord.Client):

    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        word_list = ['cheat', 'cheats', 'hack', 'hacks', 'internal', 'external', 'ddos', 'denial of service']

        # don't respond to ourselves
        if message.author == self.user:
            return

        messageContent = message.content
        if len(messageContent) > 0:
            for word in word_list:
                if word in messageContent:
                    await message.delete()
                    await message.channel.send('Do not say that!')
            
        messageattachments = message.attachments
        if len(messageattachments) > 0:
            for attachment in messageattachments:
                if attachment.filename.endswith(".dll"):
                    await message.delete()
                    await message.channel.send("No DLL's allowed!")
                elif attachment.filename.endswith('.exe'):
                    await message.delete()
                    await message.channel.send("No EXE's allowed!")
                else:
                    break

client = MyClient()
client.run('token here')
2

#Import essentials
import discord
from discord.ext import commands
import asyncio
#Some things that makes your life easier! (aliases to make code shorter)
client = commands.Bot(command_prefix='!') #change it if you want
token = 'YOUR TOKEN HERE' #Put your token here
#Making a first text command! (Respond's when a user triggers it on Discord)
@client.command()
async def hello(ctx):
    await ctx.send('Hello I am a Test Bot!')
#Tell's us if the bot is running / Runs the bot on Discord
@client.event
async def on_ready():
    print('Hello, I am now running')
    
    
    
client.run(token)
1
# bot.py
import os

import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')

client = discord.Client()

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

client.run(TOKEN)
1

New to Communities?

Join the community