Replies: 2 comments 11 replies
-
"""Slash command example using bot extension."""
import asyncio
import discord
from discord.ext import commands
# Define the bot instance.
bot = commands.Bot(command_prefix="!", self_bot=True)
@bot.event
async def on_ready():
# Log when the bot is ready.
print(f"Logged in as @{bot.user.name}({bot.user.id})!")
@bot.command()
async def bump(ctx: commands.Context):
# For this example, we are going to bump a server three times.
# Get the SlashCommand object with the command name and the
# application_id, optional, but recommended to avoid commands confusions.
command = [_ for _ in await ctx.channel.application_commands() if _.name == 'bump' and _.application_id == 1111111111111111][0]
for i in range(3):
# Invoke the slash command.
await command.__call__(channel=ctx.channel)
# Log the bump
print(f"Bumped {ctx.guild.name}({ctx.guild.id}) for the {i + 1} time into {ctx.channel.name}({ctx.channel.id}).")
# Wait before bumping again
await asyncio.sleep(7200)
print("Done !")
bot.run("YOUR_TOKEN") |
Beta Was this translation helpful? Give feedback.
-
Getting the list of slash commands is broken in the version of the package currently available on pip. For example I'm using commands = await channel.application_commands()
commands_by_name = {
cmd.name: cmd
for cmd in commands
if (
cmd.application_id == TARGET_BOT_ID
and isinstance(cmd, discord.SlashCommand)
)
} Then calling a command like commands_by_name["dooperation"](channel, operation="add", number1=23, number2=7) (or, same thing (https://docs.python.org/3/reference/datamodel.html#object.__call__): commands_by_name["dooperation"].__call__(channel, operation="add", number1=23, number2=7) ) |
Beta Was this translation helpful? Give feedback.
-
There is this bot I made and I'm trying to use the selfbot to run one of it's slash commands, however, I don't know how to access the slash commands of that bot. I have the commands ID as well so if there was a method like
channel.call_application_command(id, **kwargs)
, that would be very useful.Also I've already tried using:
and it returns None. There are tons of bots and slash commands in the server so I don't understand why it wouldn't give me any results.
I'm using Discord.py-self version v2.0.0.
Beta Was this translation helpful? Give feedback.
All reactions