Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

1
How an I use both features at once?
Post Flair (click to view more posts with a particular flair)
Post Body

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)

Comments
[not loaded or deleted]

Start by just replacing wherever it says client with bot, that should work

[not loaded or deleted]

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

[not loaded or deleted]
[not loaded or deleted]

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

[not loaded or deleted]

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.

Author
Account Strength
80%
Account Age
3 years
Verified Email
Yes
Verified Flair
No
Total Karma
599
Link Karma
411
Comment Karma
5
Profile updated: 22 hours ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago