So I am basically making a discord music bot, and I have pause command working. However I am trying to add a UI button panel to click on and pause the music. I know I could just make the pausing functionality outside of the pause command and have the music control UI call that function and same with the command, but I really do not want to do this.
I have tried everything to be able to call the command. I know you used to be able to but I guess switch to slash commands broke this.
UI Pause button code:
class MusicControls(discord.ui.View):
def __init__(self, bot):
super().__init__(timeout=None)
self.bot = bot
@discord.ui.button(label="Pause", style=discord.ButtonStyle.success, emoji="⏸️")
async def pause(self, interaction: discord.Interaction, button: discord.ui.Button):
print("Pause button clicked")
musicCog = self.bot.get_cog('AudioCommands')
await musicCog.pause(interaction)
await interaction.response.send_message("Skipped the song!", ephemeral=True)
Pause Command:
@discord.app_commandsmand(name="pause", description="Pause the currently playing song.")
async def pause(self, interaction: discord.Interaction):
print("Ran Pause")
Obviously the error is: TypeError: 'Command' object is not callable
So I am basically making a discord music bot, and I have pause command working. However I am trying to add a UI button panel to click on and pause the music. I know I could just make the pausing functionality outside of the pause command and have the music control UI call that function and same with the command, but I really do not want to do this.
I have tried everything to be able to call the command. I know you used to be able to but I guess switch to slash commands broke this.
UI Pause button code:
class MusicControls(discord.ui.View):
def __init__(self, bot):
super().__init__(timeout=None)
self.bot = bot
@discord.ui.button(label="Pause", style=discord.ButtonStyle.success, emoji="⏸️")
async def pause(self, interaction: discord.Interaction, button: discord.ui.Button):
print("Pause button clicked")
musicCog = self.bot.get_cog('AudioCommands')
await musicCog.pause(interaction)
await interaction.response.send_message("Skipped the song!", ephemeral=True)
Pause Command:
@discord.app_commandsmand(name="pause", description="Pause the currently playing song.")
async def pause(self, interaction: discord.Interaction):
print("Ran Pause")
Obviously the error is: TypeError: 'Command' object is not callable
Share Improve this question edited Mar 29 at 22:09 Clayton asked Mar 29 at 21:42 ClaytonClayton 475 bronze badges 2 |1 Answer
Reset to default 0It's messy, but you can use callback
, which is the coroutine that is executed when the slash command is called.
The below example code will call the bar
command if you press the "Pause" button. Note that None
is passed as an interaction, but since bar
only does a print it isn't needed.
import discord
from discord.ext import commands
class MusicControls(discord.ui.View):
def __init__(self, bot):
super().__init__(timeout=None)
self.bot = bot
@discord.ui.button(label="Pause", style=discord.ButtonStyle.success, emoji="⏸️")
async def pause(self, interaction: discord.Interaction, button: discord.ui.Button):
print("Pause button clicked")
bar_cmd = self.bot.tree.get_command('bar')
await bar_cmd.callback(None)
client = commands.Bot(intents=discord.Intents.all(), command_prefix='!')
@clientmand()
async def sync(ctx):
await ctx.bot.tree.sync()
@client.treemand(name='foo')
async def foo(interaction: discord.Interaction):
await interaction.response.send_message('test', view=MusicControls(client))
@client.treemand(name='bar')
async def bar(interaction: discord.Interaction):
print("called")
client.run('token')
pause_music
and call it in both commands/buttons? – Łukasz Kwieciński Commented Mar 29 at 22:03