0

I am creating autovc command for my discord bot but I ran into some error. Code:

@client.command()
async def autovc(ctx):
    def check(message):
        return message.author == ctx.author
    await ctx.send("Please enter the channel name you want to create?")
    c_name= await client.wait_for('message', check=check)
    await ctx.send("What would be the channel user limit?")
    c_limit= int((await client.wait_for('message', check=check)).content)
    await ctx.send("Please Enter the Category ID in which tha channel will be created.")
    guild = client.get_guild(852866665371926588)
    ctg= discord.utils.get(guild.categories, id=(int((await client.wait_for('message', check=check)).content)))
    await guild.create_voice_channel(name= c_name, category= ctg, user_limit= c_limit)

Error:

File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "d:\BOT\test.py", line 30, in autovc await guild.create_voice_channel(name= c_name, category= ctg, user_limit= c_limit)

File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\guild.py", line 987, in create_voice_channel data = await self.create_channel(name, overwrites, ChannelType.voice, category, reason=reason, **options) File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 156, in request kwargs['data'] = utils.to_json(kwargs.pop('json')) File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\utils.py", line 328, in to_json return json.dumps(obj, separators=(',', ':'), ensure_ascii=True) File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\json_init.py", line 234, in dumps return cls( File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 257, in iterencode return _iterencode(o, 0) File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 179, in default raise TypeError(f'Object of type {o.class.name} '

TypeError: Object of type Message is not JSON serializable

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\illus\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: Object of type Message is not JSON serializable

3
  • What's the traceback for the initial exception? Commented Aug 13, 2021 at 7:08
  • Updated! I'd put whole terminal output there. Commented Aug 13, 2021 at 7:14
  • I'd recommend going for inputting the required arguments (channel name, category ID, user limit) using the command directly, like so: async def autovc(ctx, c_name: str, c_categid: int, c_limit: int): Commented Sep 29, 2021 at 7:15

1 Answer 1

2

I think it is happening because you are trying to name your vc with message object and not string. Instead of putting c_name as name parameter try putting c_name.content so you get the actual contents of the message. Like this:

await guild.create_voice_channel(name=c_name.content, category=ctg, user_limit=c_limit)

I haven't tested it but I'm pretty sure that's the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.