Skip to content

How to use a .cs plugin #1068

@canyu0

Description

@canyu0

Describe the problem
error when loading a plugin

To Reproduce
plugins/MyPlugin.cs

using System;
using System.Threading.Tasks;
using TS3AudioBot;
using TS3AudioBot.Audio;
using TS3AudioBot.CommandSystem;
using TS3AudioBot.Plugins;
using TSLib.Full.Book;

public class NowPlaying : IBotPlugin /* or ICorePlugin */
{
    private PlayManager playManager;
    private Ts3Client ts3Client;
    private Connection serverView;

    // Your dependencies will be injected into the constructor of your class.
    public NowPlaying(PlayManager playManager, Ts3Client ts3Client, Connection serverView)
    {
        this.playManager = playManager;
        this.ts3Client = ts3Client;
        this.serverView = serverView;
    }

    const string NowPlayingTag = " [Now Playing]";
    string lastName = null;

    // The Initialize method will be called when all modules were successfully injected.
    public void Initialize()
    {
        playManager.AfterResourceStarted += Start;
        playManager.PlaybackStopped += Stop;
    }

    private async Task Start(object sender, EventArgs e)
    {
        var self = serverView.OwnClient;
        if (self == null) return;
        lastName = self.Name;
        await ts3Client.ChangeName(lastName.EndsWith(NowPlayingTag) ? lastName : lastName + NowPlayingTag);
    }

    private async Task Stop(object sender, EventArgs e)
    {
        if (lastName != null) await ts3Client.ChangeName(lastName);
    }

    // You should prefer static methods which get the modules injected via parameter unless
    // you actually need objects from your plugin in your method.
    [Command("hello")]
    public static string CommandHello(PlayManager playManager, string name)
    {
        if (playManager.CurrentPlayData != null)
            return "hello " + name + ". We are currently playing: " + playManager.CurrentPlayData.ResourceData.ResourceTitle;
        else
            return "hello " + name + ". We are currently not playing.";
    }

    public void Dispose()
    {
        // Don't forget to unregister everything you have subscribed to,
        // otherwise your plugin will remain in a zombie state
        playManager.AfterResourceStarted -= Start;
        playManager.PlaybackStopped -= Stop;
    }
}

!plugin list
error in console:Error L37/C24: 'ClientId' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'ClientId' could be found (are you missing a using directive or an assembly reference?)

System Information

  • Platform: Ubuntu 20.04

dotnet --version:8.0.411

  • Which commit did you download: (or on prebuilt: mono TS3AudioBot.exe -V)

release 0.12.0

Additional Logs, Exceptions, etc

2025-07-02 11:09:39.1316| INFO|Core|Setup.LogHeader [============ TS3AudioBot started =============]
2025-07-02 11:09:39.1870| INFO|Core|Setup.LogHeader [ Date: Wednesday, 02 July 2025 11:09:39
2025-07-02 11:09:39.2773| INFO|Core|Setup.LogHeader [ Version: 0.12.0/master/768c1867
2025-07-02 11:09:39.2773| INFO|Core|Setup.LogHeader [ Build: Release
2025-07-02 11:09:39.2773| INFO|Core|Setup.LogHeader [ Platform: Ubuntu 20.04.6 LTS (Focal Fossa) (64bit)
2025-07-02 11:09:39.2773| INFO|Core|Setup.LogHeader [ Runtime: .NET Framework 3.1.13 ServerGC:True GC:SustainedLowLatency
2025-07-02 11:09:39.2773| INFO|Core|Setup.LogHeader [ Opus: libopus 1.3.1 (x64)
2025-07-02 11:09:39.2773| INFO|Core|Setup.LogHeader [==============================================]
2025-07-02 11:09:39.7615| INFO|Core|WebServer.StartWebServerInternal Starting Webserver on port xxxxx
2025-07-02 11:09:39.9594| INFO|Core|Bot.Run Bot "default" connecting to "xxx"
2025-07-02 11:09:40.4017| INFO|Core|Ts3Client.ConnectClient Client connected.
2025-07-02 11:09:44.2400| INFO|0|Bot.OnMessageReceived User canyu0 requested: !plugin load 0
2025-07-02 11:09:44.3185| WARN|0|RightsManager.ReadFile Rule has no matcher and will always match
2025-07-02 11:09:44.3191| WARN|0|RightsManager.ReadFile Rule has no matcher and will always match
2025-07-02 11:09:46.1665| WARN|0|Plugin.PrepareSource Plugin "MyPlugin.cs" [0] compiler notifications:
Error L37/C24: 'ClientId' does not contain a definition for 'Name' and no accessible extension method 'Name' accepting a first argument of type 'ClientId' could be found (are you missing a using directive or an assembly reference?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions