【问题标题】:I'm trying to make an automated BannedUser message and it says I'm missing a parameter我正在尝试制作一条自动 BannedUser 消息,它说我缺少一个参数
【发布时间】:2018-06-03 02:16:08
【问题描述】:

错误:“UserBanned”没有重载匹配委托“Func”

我知道我被禁止的用户消息缺少一个参数,并且我知道我必须在该参数的括号中添加一些内容,但我完全不知道我应该输入什么。我已经寻找了一两个小时,也许答案就在我脸上,但我不知道,但我仍然不知道该怎么办。我想我应该在括号中添加一个变量,但我不确定是什么。

public async Task RunBotAsync()
    {
        _client = new DiscordSocketClient(new DiscordSocketConfig
        {
            LogLevel = LogSeverity.Verbose
        });
        _commands = new CommandService();
        _services = new ServiceCollection()
            .AddSingleton(_client)
            .AddSingleton(_commands)
            .BuildServiceProvider();

        string botToken = "Token";

        //event subscriptions
        _client.Log += Log;
        _client.UserJoined += UserJoined;
        _client.UserLeft += UserLeft;
        _client.UserBanned += UserBanned; //<- Error Line

        await RegisterCommandsAsync();

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

        await _client.StartAsync();

        await Task.Delay(-1);
    }

    private async Task UserBanned(SocketGuildUser user, IGuild bloop)
    {
        var guild = user.Guild;
        var announcements = _client.GetChannel(390418472783577088) as SocketTextChannel;
        await announcements.SendMessageAsync($"{user.Mention} was banned from the server.");
    }

【问题讨论】:

  • 为什么您的帖子中没有包含确切的错误消息?为什么你还没有确定是哪条线路造成的?这些细节就在你面前的屏幕上。它们也会对我们有用。
  • 这样更好吗?

标签: c# discord discord.net


【解决方案1】:

从行:

_client.UserBanned += UserBanned;

引用的函数应该如下所示。

async Task UserBanned(SocketUser user, SocketGuild bloop)
{
    var guild = user.Guild;
    var announcements = _client.GetChannel(390418472783577088) as SocketTextChannel;
    await announcements.SendMessageAsync($"{user.Mention} was banned from the server.");
}

Discord.WebSocket.BaseSocketClient.UserBanned

看起来您需要一个 SocketGuild arg 而不是 IGuild 接口。

【讨论】:

  • 我将 IGuild 更改为 SocketGuild 但它仍然给我同样的错误。括号中的内容是否应该与之相关?
  • 这正是我的代码的样子,但我仍然遇到同样的错误。
猜你喜欢
  • 2020-11-14
  • 1970-01-01
  • 2023-01-13
  • 1970-01-01
  • 2016-05-22
  • 2019-06-21
  • 1970-01-01
  • 2010-11-26
  • 2019-10-22
相关资源
最近更新 更多