This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I want to use the client.event feature and the Bot.command feature in the same bot. The client.event features work but the Bot.command features do not. (discord.py)
Code:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import os
import requests
import json
import random
from replit import db
from PIL import Image
from io import BytesIO
from keep_alive import keep_alive
client = discord.Client()
def get_quote():
response = requests.get("https://zenquotes.io/api/random")
json_data = json.loads(response.text)
quote = json_data[0]['q'] " -" json_data[0]['a']
return(quote)
u/client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
#when the bot is ready to be used. 0 will be replaced with .format(client) (the bot)
u/client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
if msg.startswith('.quote'):
quote = get_quote()
await message.channel.send(quote)
if msg.startswith("bug town"):
await message.channel.send("NOPE")
if msg.startswith('bug simp'):
await message.author.send(file=discord.File('Ayo.jpg'))
await message.author.send(file=discord.File('WTH.jpg'))
await message.author.send(file=discord.File('download.jpg'))
if msg.startswith('bug help'):
await message.author.send("bug town - Sends a modified version of 'Old Town Road by Lil Nas X' \nbug simp - Send you some sus stuff \nbug help - Sends you this message")
await message.channel.send('***A HELP MESSAGE HAS BEEN SENT***')
Token = os.environ['TOKEN']
bot = commands.Bot(command_prefix='$')
u/bot.command
async def ping(ctx):
await ctx.send(f'Pong! {client.latency * 1000}')
keep_alive()
client.run(Token)
Let's go back to the basic house example many people use when explaining classes. Let's say you have a blueprint for a house with a roof, and then you have another blueprint for the exact same house house except this one has a roof. Essentially what you're doing is saying I want to build a house with a roof, so I'm going to build a house with a roof and one house without it. All this does for you is take longer and waste materials, when you could have just built one house with a roof
Let's go back to the basic house example many people use when explaining classes. Let's say you have a blueprint for a house with a roof, and then you have another blueprint for the exact same house house except this one has a roof. Essentially what you're doing is saying I want to build a house with a roof, so I'm going to build a house with a roof and one house without it. All this does for you is take longer and waste materials, when you could have just built one house with a roof
commands.Bot subclasses discord.Client, essentially meaning that commands.Bot has literally everything that discord.Client has as well as it's own interface/class features on top of it. You don't need to use both.
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Discord_Bot...
Start by just replacing wherever it says client with bot, that should work