How can I do the command with /?

How can i do the command with /?
So im making a discord bot and I want to make the same command from my second comment.
When I used "client.command I was able to make a function. I cant do that where my first comment is located. This problem is going to effect my “8ball” command too.

Repl link:
https://replit.com/@Pycratch/PYCRATCHBOT

code snippet
import os
import discord
from discord.ext import commands, tasks
import random
from itertools import cycle
from keep_alive import keep_alive

client = commands.Bot(command_prefix="=", intents=discord.Intents.all())
my_secret = os.environ['discord_toekn']
bot_commands = """
'=8ball' + {message}: magic eight ball
  '=sendmeamessage': the bot seds you a message
  '=custom_message': you tell the bot to send you a custom message
  '=ping': view bot ping
  '=random_number': the bot will tell you a random number between 0 and 1000000000000
  '/hello': bot responds with 'hello' to you
  more commands coming soon
"""


bot_status = cycle(["type '=commands' for help","pls type '=commands' for help"])

@tasks.loop(seconds=5)
async def change_status():
  await client.change_presence(activity=discord.Game(next(bot_status)))

@client.event
async def on_ready():
    print("Bot is connected to Discord")
    change_status.start()
  

@client.event
async def on_message(message):
  if message.author == client.user:
    return
  if message.content.startswith('/hello'):
    await message.channel.send("Hello")
  if message.content.startswith("/ping"):
    bot_latency = round(client.latency * 1000)
    await message.channel.send(f"pong ! {bot_latency} ms.")
  if message.content.startswith("/commands"):
    await message.channel.send(bot_commands)
  if message.content.startswith("/sendmeamessage"):
    await message.author.send("I JUST SENT U A MESSAGE")
  if message.content.startswith("/8ball"):
    with open("responses_eightall.txt", "r") as f:
      random_responses = f.readlines()
      response = random.choice(random_responses)
    await message.channel.send(response)
  if message.content.startswith("/custom_message"):
    pass #my problem is located here

@client.command()
async def ping(ctx):
  bot_latency = round(client.latency * 1000)
  await ctx.send(f"pong ! {bot_latency} ms.")

@client.command()
async def sendmeamessage(ctx):
  await ctx.author.send("I JUST SENT U A MESSAGE")

@client.command(aliases=["8ball", "8 ball", "eight ball"])
async def magic_eightball(ctx, *, question):
  with open("responses_eightall.txt", "r") as f:
    random_responses = f.readlines()
    response = random.choice(random_responses)
  await ctx.send(response)
@client.command()
async def custom_message(ctx, *, message):#i want to create this command above using / not =
  await ctx.author.send(message)

@client.command()
async def random_number(ctx):
  random_number = random.randint(0, 1000000000000)
  await ctx.send(random_number)

@client.command()
async def commands(ctx):
  await ctx.send(bot_commands)

keep_alive()

client.run(my_secret)

according to

discord.py is deprecated and IIRC you can’t use slash_commands since those changes were not added pre deprecation. You should switch to an actively maintained version like pycord:

3 Likes

I do still use py-cord though because it was easy to migrate to from prefix commands

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.