My code for the prefix command:
import discord
from discord.ext import commands
class Ping(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def ping(self, ctx):
message = await ctx.send("Pong!")
latency = self.bot.latency * 1000
await message.edit(content=f'Pong! **{latency:.2f} ms**')
async def setup(bot):
await bot.add_cog(Ping(bot))
For the slash command:
import discord
from discord import app_commands
from discord.ext import commands
class sPing(commands.Cog):
def __init__(self, bot):
self.bot = bot
@app_commands.command()
async def ping(self, interaction: discord.Interaction):
latency = self.bot.latency * 1000
await interaction.response.send_message(content='Pong!')
msg = await interaction.original_response()
await msg.edit(content=f'Pong! **{latency:.2f} ms**')
async def setup(bot):
await bot.add_cog(sPing(bot))
Is there a way for me to like stop repeating this and can make the prefix command and slash command together in the same chunk of code?