Это код:
Код: Выделить всё
import discord
from discord.ext import commands
from datetime import datetime
intents = discord.Intents.all()
intents.message_content = True
bot = commands.Bot(command_prefix="/", intents=intents)
# Fetch the token from environment variables
token = 'token'
# Ensure you set 'DISCORD_TOKEN' in your .env file
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
print("Registered commands:")
for command in bot.tree.get_commands():
print(f"- {command.name}: {command.description}")
await bot.tree.sync()
print("Commands synced.")
@bot.event
async def on_message(message):
if message.author == bot.user:
return
user = str(message.author)
user_message = str(message.content)
channel = str(message.channel.name)
print(f'Message {user_message} by {user} on {channel}')
if channel == "test":
if user_message.lower() == "hi":
await message.channel.send(f"Hey {user}")
elif user_message.lower() == "joke": # Corrected the joke condition
await message.channel.send("What did the perfume say to the sweat when it defeated it?\nDon't be salty!!")
await bot.process_commands(message)
def convert_to_unix_timestamp(date_time):
date_obj = datetime.strptime(date_time, '%Y-%m-%d %H:%M:%S')
timestamp = int(date_obj.timestamp())
return timestamp
@commands.hybrid_command(name="ping", description="To Test connectivity")
async def ping(ctx):
await ctx.defer()
await ctx.send("Pong!")
@bot.hybrid_command(name="time")
async def time(ctx, date, time):
date_time = f"{date} {time}"
stamp = convert_to_unix_timestamp(date_time)
await ctx.send(f"")
bot.add_command(ping)
# Use the token variable for running the bot
bot.run(token)
Я ожидал, что это сработает без проблем, потому что я сделал все, что мог, я использовал app_commands, теперь используя Hybrid_commands.
при использовании команды в качестве команды с префиксом она работает, но в качестве команды с косой чертой - нет.
Подробнее здесь: https://stackoverflow.com/questions/792 ... discord-py