Home > Blockchain >  Bot not responding discord.py
Bot not responding discord.py

Time:12-17

Here is my code

import discord
from discord.ext import commands
TOKEN = "MY TOKEN"
import random

intent = discord.Intents.default()
intent.members = True
intent.message_content = True

client = discord.Client(intents=intent)

bot = commands.Bot(command_prefix='--', intents=discord.Intents.default())

slap_gif = ['https://media.tenor.com/GBShVmDnx9kAAAAC/anime-slap.gif', 'https://media.tenor.com/CvBTA0GyrogAAAAC/anime-slap.gif', 'https://i.pinimg.com/originals/fe/39/cf/fe39cfc3be04e3cbd7ffdcabb2e1837b.gif', 'https://i.pinimg.com/originals/68/de/67/68de679cc20000570e8a7d9ed9218cd3.gif']

slap_txt = ['Ya, you deserve it', 'Get slapped', 'Ya, get slapped hard']

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@bot.command()
async def slap(ctx):
    embed = discord.Embed(
        color=discord.Color("#ee5253"),
        description = f"{ctx.author.mention} {(random.choice(slap_txt))}"
    )

    embed.set_image(url=(random.choice(slap_gif)))

    await ctx.send(embed=embed)

client.run(TOKEN)

I am trying to create a basic gif action bot but it is not working, it was working with on_message but i switched to @bot.command and it is not working now. it runs with no error.

CodePudding user response:

on_message reacts on any text you send. @bot.command() just reacts to the the command name with the prefix, which would be in your case --slap.

I just can guess, but eventually you didn't send the correct message text.

Because discord.Bot is a subclass of discord.Client you only need exactly one of the two (because you register the command bot, but you run client, the command registered on bot won't work. Also preferably you should keep the discord.Bot instance which is named bot because it as it is a subclass it has more functionality) and you should replace all occurrences of client with that.

Also your bot seems to have the wrong intents. If I change bot = commands.Bot(..., intents=discord.Intents.default()) to bot = commands.Bot(..., intents=intent) it ran the slap function (It has thrown an error for me, but that's not the topic of this question).

  • Related