C# 我想为我的机器人更改Discord服务器中的游戏活动,我该怎么做?

C# 我想为我的机器人更改Discord服务器中的游戏活动,我该怎么做?,c#,discord,C#,Discord,这是我的代码program.cs private DiscordSocketClient _client; private CommandService _commands; private IServiceProvider _services; public async Task RunBotAsync() { _client = new DiscordSocketClient(); _commands = new Com

这是我的代码program.cs

    private DiscordSocketClient _client;
    private CommandService _commands;
    private IServiceProvider _services;
    public async Task RunBotAsync()
    {
        _client = new DiscordSocketClient();
        _commands = new CommandService();

        _services = new ServiceCollection()
            .AddSingleton(_client)
            .AddSingleton(_commands)
            .BuildServiceProvider();

        string botToken = "";

        _client.Log += Log;
        _client.UserJoined += AnnounceUserJoined;
        _client.UserIsTyping += UserIsTyping;

        await RegisterCommandsAsync();

        await _client.LoginAsync(Discord.TokenType.Bot, botToken);

        await _client.StartAsync();

        await Task.Delay(-1);


    }

    private async Task AnnounceUserJoined(SocketGuildUser user)
    {
        var guild = user.Guild;
        var channel = guild.DefaultChannel;
        await channel.SendMessageAsync($"Welcome, {user.Mention} nice to see you! (≧∇≦)ノ");
    }
    private async Task UserIsTyping(SocketUser u, ISocketMessageChannel m)
    {
        int random = new Random().Next(0, 10);
        string username = u.Username;
        if (random == 5)
        {
            await m.SendMessageAsync("*Watcha typin " + username + "? ( ͡° ͜ʖ ͡°)*");
        }

    }

    private Task Log(LogMessage arg)
    {
        Console.WriteLine(arg);

        return Task.CompletedTask;

    }

    public async Task RegisterCommandsAsync()
    {
        _client.MessageReceived += HandleCommandAsync;

        await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
    }

    private async Task HandleCommandAsync(SocketMessage arg)
    {
        var message = arg as SocketUserMessage;

        if (message is null || message.Author.IsBot) return;

        int argPos = 0;

        if (message.HasStringPrefix("$", ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))
        {
            var context = new SocketCommandContext(_client, message);

            var result = await _commands.ExecuteAsync(context, argPos, _services);

            if (!result.IsSuccess)
                Console.WriteLine(result.ErrorReason);
        }
    }

}
}

我尝试了很多东西,但都没有成功

除此之外,所有其他命令都可以正常工作

在游戏活动中,站着“玩游戏”会很酷。 我在Discord.NET中使用它。 甚至可以用Discord.NET来显示它吗

这是我的第一个问题,谢谢你的回答

我在c#vs 2020上使用windows

请帮忙
谢谢:)

您需要使用
wait Context.Client.SetGameAsync(“”)
更改游戏活动。在启动bot时或在可以访问
上下文
客户端
(您的bot客户端)的命令中使用此选项。

这将位于您的
DiscordSocketClient
下,因此您的
\u客户端
位于此处。使用
\u client.SetGameAsync()

使用
Context.client.SetGameAsync()
出现此错误:CS0103 C#名称“Context”在当前上下文中不可用。您尝试在哪里设置游戏?如果是在命令的上下文中,这就行了。我知道了,谢谢:)