full dicord.py bot code code example
Example 1: python discord bot moderate chat
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']
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')
Example 2: discord.py
Docs = "https://discordpy.readthedocs.io/en/latest/"
PyPI = "pip install -U discord.py"
import discord
from discord.ext import commands
client = commands.Bot(comand_prefix='bot prefix here')
@client.event()
async def on_ready():
print(f"Bot online and logged in as {client.user}")
@client.command(aliases=["ms", "aliases!"])
async def ping(ctx, a_variable):
await ctx.send(f"Pong! {round(client.latency * 1000)}ms. Your input was {a_variable}")
client.run('your token here')