xxxxxxxxxx
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
# don't respond to ourselves
if message.author == self.user:
return
if message.content == 'ping':
await message.channel.send('pong')
client = MyClient()
client.run('token')
Discord.py is a modern and easy to use Python API wrapper for discord. It has a wide variety of features for any bot project! I tend to use repl.it to program my bots, but you can use whatever you wish. Head to the following website to create your bot:
https://discord.com/developers/applications
Here's a discord.py 8ball bot that supports slash commands:
xxxxxxxxxx
import discord
from discord.ext import commands
import random
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
responses = ["yes", "no", "maybe"]
@bot.event
async def on_ready():
print("[LOG] Logged in.")
try:
synced = bot.tree.sync()
print(f"[LOG] Synced {len(synced)} commands.")
except Exception as e:
print(f"[ERROR] {e}")
@bot.tree.command(aliases=["8ball"])
async def eight_ball(interaction: discord.Interaction, question: str):
await interaction.response.send_message(random.choice(responses))
bot.run("YOUR-BOT-TOKEN-HERE")
If you need any help or support, message me on discord XSussicaX!