Reputation: 35
I am trying to make a simple music bot. When I execute the command I get this error: discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.
This is my code:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix= "-")
class VoiceConnectionError(commands.CommandError):
"""Custom Exception class for connection errors."""
...
class InvalidVoiceChannel(VoiceConnectionError):
"""Exception for cases of invalid Voice Channels."""
...
@bot.event
async def on_ready():
print('Bot ready')
@bot.command(name='connect', aliases=['join'])
async def connect(self, ctx, *, channel: discord.VoiceChannel=None):
await ctx.send(f'Connected to: **{channel}**', delete_after=10)
bot.run('TOKEN')
The command should move the bot into the voice channel in discord.
This is the full traceback:
Full traceback:
Ignoring exception in command connect:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 859, in invoke
await ctx.command.invoke(ctx)
File "/anaconda3/lib/python3.6/site-packages/discord/ext/commands/core.py", line 718, in invoke
await self.prepare(ctx)
File "/anaconda3/lib/python3.6/site-packages/discord/ext/commands/core.py", line 682, in prepare
await self._parse_arguments(ctx)
File "/anaconda3/lib/python3.6/site-packages/discord/ext/commands/core.py", line 596, in _parse_arguments
transformed = await self.transform(ctx, param)
File "/anaconda3/lib/python3.6/site-packages/discord/ext/commands/core.py", line 442, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.
Upvotes: 0
Views: 2634
Reputation: 60944
Your commands should only accept a self
parameter if they are part of a cog. Remove the parameter:
@bot.command(name='connect', aliases=['join'], pass_context=True)
async def connect(ctx, *, channel: discord.VoiceChannel=None):
...
Upvotes: 1