获取用户活动和游戏状态



我正在编写我的第一个机器人,我希望它检查用户的活动状态,并根据他们在玩什么。机器人程序获取用户,但用户状态始终处于脱机状态因此,它无法获取他们的活动。

我已启用服务器成员和存在意图。

这是我的启动代码,我需要在这里添加一些东西吗?

static void Main(string[] args) => new Program().RunBotAsync().GetAwaiter().GetResult();
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 token = "my token"; 
_client.Log += _client_Log;

await RegisterCommandsAsync();
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();

await Task.Delay(-1);
}

试试这个:


private DiscordSocketClient _client;
private CommandService _commands;
private IServiceProvider _services;

public async Task RunBotAsync()
{

_client = new DiscordSocketClient();
_commands = new CommandService();

_services = new ServiceCollection()
.AddSingleton(new DiscordSocketClient(new DiscordSocketConfig
{
GatewayIntents =  GatewayIntents.AllUnprivileged |
GatewayIntents.GuildPresences | GatewayIntents.GuildMembers
}))
.AddSingleton(_commands)
.BuildServiceProvider();

string token = "my token"; 

_client.Log += _client_Log;

await RegisterCommandsAsync();

await _client.LoginAsync(TokenType.Bot, token);

await _client.StartAsync();

await Task.Delay(-1);

}

最新更新