Может ли мой бот Discord включать в себя как префиксные, так и косые команды?Python

Программы на Python
Anonymous
Может ли мой бот Discord включать в себя как префиксные, так и косые команды?

Сообщение Anonymous »

Мой код для префиксной команды:

Код: Выделить всё

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))
Для команды косой черты:

Код: Выделить всё

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))
Можно ли мне перестать повторять это и объединить команду префикса и команду косой черты в одном фрагменте кода?

Подробнее здесь: https://stackoverflow.com/questions/785 ... h-commands

Вернуться в «Python»