TheHolyWaffle / TeamSpeak-3-Java-API

A Java wrapper of TeamSpeak's 3 server query API.
MIT License
306 stars 107 forks source link

Convert Error (ID 1540) by trying to edit a channel codec #341

Closed ghost closed 5 years ago

ghost commented 5 years ago

I tried to register a new bot command for editting a channel by the bot. The channel properties "Codec" and "Quality" should be changed by the bot when receiving a message.

`@Override public void onTextMessage(TextMessageEvent e) {

            for (Client c : Main.api.getClients()) {
                if (c.isInServerGroup(6)) {
                    if (e.getMessage().toLowerCase().equalsIgnoreCase("!musikchannel")) {
                        Main.api.editChannel(c.getChannelId(), ChannelProperty.CHANNEL_CODEC, "Opus Musik");
                        Main.api.editChannel(c.getChannelId(), ChannelProperty.CHANNEL_CODEC_QUALITY, "10");
                    }
                    if (e.getMessage().toLowerCase().equalsIgnoreCase("!defaultchannel")) {
                        Main.api.editChannel(c.getChannelId(), ChannelProperty.CHANNEL_CODEC, "Opus Voice");
                        Main.api.editChannel(c.getChannelId(), ChannelProperty.CHANNEL_CODEC_QUALITY, "10");
                    }
                }

            }
        }`

But the bot returns the following error message:

`2019-08-31 13:33:45.500 [DEBUG] TS3 command error: {msg=convert error, id=1540} 2019-08-31 13:33:45.507 [ERROR] Event listener threw an exception com.github.theholywaffle.teamspeak3.api.exception.TS3CommandFailedException: A "channeledit" command returned with a server error.

convert error (ID 1540) at com.github.theholywaffle.teamspeak3.api.CommandFuture.checkForFailure(CommandFuture.java:415) at com.github.theholywaffle.teamspeak3.api.CommandFuture.getUninterruptibly(CommandFuture.java:356) at com.github.theholywaffle.teamspeak3.TS3Api.editChannel(TS3Api.java:1518) at de.minecraftag.controlbot.Events$1.onTextMessage(Events.java:38) at com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent.fire(TextMessageEvent.java:69) at com.github.theholywaffle.teamspeak3.EventManager$ListenerTask.run(EventManager.java:169) at com.github.theholywaffle.teamspeak3.TS3Query.lambda$submitUserTask$0(TS3Query.java:232) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) `

Please help me or comment my mistake(s).

rogermb commented 5 years ago
Main.api.editChannel(c.getChannelId(), ChannelProperty.CHANNEL_CODEC, "Opus Musik");

The server expects an ID that corresponds to some codec, not the name of that codec. We've provided the Codec enum for that purpose - though I must admit the current implementation kinda doesn't lend itself to be used in editChannel... Your code then becomes

String codecId = Integer.toString(Codec.OPUS_MUSIC.getIndex());
Main.api.editChannel(c.getChannelId(), ChannelProperty.CHANNEL_CODEC, codecId);

That should hopefully get rid of that convert error 😄

ghost commented 5 years ago

Hey,

thanks for your helpful response. The "bug" is now fixed and the bot works successfully. :)

rogermb commented 5 years ago

Awesome, glad to hear that 😄