#πŸ”’ everything works, but my slash command wont sync?

32 messages Β· Page 1 of 1 (latest)

vernal magnet
#

main code

import os
import discord
from dotenv import load_dotenv
from discord.ext import commands
import asyncio

intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="!", intents=discord.Intents.all(), application_id=1344570304046956544)

async def load():
    for filename in os.listdir("./cogs"):
        if filename.endswith("py"):
            await client.load_extension(f"cogs.{filename[:-3]}")
            print("Loaded.")
            

@client.event
async def on_ready():
    print(f"Active")
    synced = await client.tree.sync()
    print(f"Synced {len(synced)} command(s).")
    
asyncio.run(load())

if __name__ == "__main__":
    client.run("no no")

spiral girderBOT
#

@vernal magnet

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

vernal magnet
#

cog file

from discord.ext import commands
import requests
import discord


def fetch_user_id(username: str):
    response = requests.post(
        "https://users.roblox.com/v1/usernames/users",
        json = {
            "usernames": [username], 
            "excludeBannedUsers": True
        }
    )

    return response.json()["data"][0]["id"]

def fetch_avatar(user_id: int):
    response = requests.get(
        "https://thumbnails.roblox.com/v1/users/avatar",
        params = {
            "userIds": [user_id],
            "size": "420x420",
            "format": "Png",
            "isCircular": "false"
        }
    )

    return response.json()["data"][0]["imageUrl"]

class Kos(commands.Cog, name="Kos"):
    print("received")

    def __init__(self, bot: commands.Bot):
        self.bot = bot
        

        

    @discord.app_commands.command(name = "kos", description = "Publishes a KOS notice on the specified user")
    async def kos(self, interaction: discord.Interaction, username: str, reason: str):
        
        targetchannel = self.bot.get_channel(1343882206053142580)
        user_id = fetch_user_id(username)
        avatar_url = fetch_avatar(user_id)

        embed = discord.Embed(
            color = 0xff0000,
            title = f"USERNAME: {username}", url=f"https://www.roblox.com/users/{user_id}/profile",
            description = f"**Reason:** {reason}\n**Issued By:** <@{interaction.user.id}>"
        )

        embed.set_author(name = "KILL ON SIGHT NOTICE")
        embed.set_image(url = avatar_url)
        embed.set_footer(text = "If user is seen you are authorised to shoot, regardless of your rank witin the nowhere ville comedy club")

        
        await targetchannel.send("<@&1343881957771186257>", embed = embed)
        await interaction.response.send_message(f"KOS Notice sucessfully posted on {username}!")

async def setup(client):
    await client.add_cog(Kos(client), guilds=[discord.Object(id="1341723521906114643")])
bleak jetty
#

whats the output of the print sync?

upbeat zealot
#

I wouldn't recommend syncing every time you start up the bot, I think you get ratelimited if you sync too many times?

bleak jetty
#

why not?

#

i do dat

#

how do you literally

#

thats how its supposed to be used no?

vernal magnet
bleak jetty
#

amazing 🌟

#

can you try shoving the command into the main script if it works, if it does, then we can norrow it down to a cog issue

vernal magnet
#

even though theres a command πŸ’”

vernal magnet
bleak jetty
vernal magnet
#

ohhh

#

yeah i get what you mean

bleak jetty
#

i think we want some prints in the load coro idk, i dont do cogs havent tried them

#

wait what?

#

you really load cogs by adding a completely unbound load coro?

#

i think thats the issue no?

vernal magnet
#

im not sure, im just confused

upbeat zealot
vernal magnet
upbeat zealot
vernal magnet
#
import os
import discord
from dotenv import load_dotenv
from discord.ext import commands
import asyncio

intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="!", intents=discord.Intents.all(), application_id=1344570304046956544)

async def load():

    for filename in os.listdir("./cogs"):
        if filename.endswith("py"):
            await client.load_extension(f"cogs.{filename[:-3]}")
            print("Loaded.")
            


@client.event
async def on_ready():
    await load()
    print(f"Active")
    synced = await client.tree.sync()
    print(f"Synced {len(synced)} command(s).")

if __name__ == "__main__":
    client.run("tok")


upbeat zealot
#

does your command show up in your server?

vernal magnet
#

No

upbeat zealot
#

reload your discord

spiral girderBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.