所以我制作了一个不和谐的机器人,由于某种原因我看不到我创建的斜杠命令。
斜线命令
[SlashCommand("ping", "Receive a ping message")]
public async Task HandlePingCommand()
{
await RespondAsync("Stop pinging me!");
}
我几乎可以肯定这与机器人权限有关。 我已经设置了 GatewayIntents AllUnprivileged 和 MessageContent。
添加信息
if (IsDebug())
await sCommands.RegisterCommandsToGuildAsync("my server id"));
else
await sCommands.RegisterCommandsGloballyAsync(true);
我还添加了 applications.commands 范围
如果需要更多信息和/或代码,我当然会添加它。
我也遇到了同样的问题,这就是我的解决方法:
class
传递到了 API 不支持的命令方法中:No type TypeConverter is defined for this Discord.WebSocket.SocketSlashCommand
)_client.Log += message => // this one
{
Console.WriteLine(message);
return Task.CompletedTask;
};
// other code
_client.Ready += OnClientReady;
await _client.LoginAsync(TokenType.Bot, discordToken);
await _client.StartAsync();
GatewayIntents.All
var config = new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.All
};
private async Task OnClientReady()
{
_client.Ready -= OnClientReady;
_interactionService = new InteractionService(_client);
await _interactionService.AddModulesAsync(Assembly.GetExecutingAssembly(), _serviceProvider);
await _interactionService.RegisterCommandsGloballyAsync();
_client.InteractionCreated += async interaction =>
{
var scope = _serviceProvider.CreateScope();
var ctx = new SocketInteractionContext(_client, interaction);
try
{
await _interactionService.ExecuteCommandAsync(ctx, scope.ServiceProvider);
}
catch (Exception ex)
{
Console.WriteLine($"Error executing command: {ex.Message}");
}
};
}