Discord.Net如何列出组中的所有命令 公共课cmd_数学 继承ModuleBase #区域“添加” 公共异步函数cmdAdd(ByVal num1为整数,ByVal num2为整数)作为任务 点心=num1+num2 Dim user=Context.user Dim channel=Context.channel wait channel.SendMessageAsync($“{user.antify}指定的两个数字之和为{sum}”) 端函数 #末端区域 #区域“减法” 作为任务的公共异步函数cmdSub(ByVal num1作为整数,ByVal num2作为整数) 点心=num1-num2 Dim user=Context.user Dim channel=Context.channel wait channel.SendMessageAsync($“{user.antify}指定的两个数字之和为{sum}”) 端函数 #末端区域 #区域“倍增” 公共异步函数cmdMulti(ByVal num1为整数,ByVal num2为整数)作为任务 点心=num1*num2 Dim user=Context.user Dim channel=Context.channel wait channel.SendMessageAsync($“{user.antify}指定的两个数字之和为{sum}”) 端函数 #末端区域 #区域“分化” 公共异步函数cmdDivide(ByVal num1为整数,ByVal num2为整数)作为任务 点心=num1/num2 Dim user=Context.user Dim channel=Context.channel wait channel.SendMessageAsync($“{user.antify}指定的两个数字之和为{sum}”) 端函数 #末端区域 末级

Discord.Net如何列出组中的所有命令 公共课cmd_数学 继承ModuleBase #区域“添加” 公共异步函数cmdAdd(ByVal num1为整数,ByVal num2为整数)作为任务 点心=num1+num2 Dim user=Context.user Dim channel=Context.channel wait channel.SendMessageAsync($“{user.antify}指定的两个数字之和为{sum}”) 端函数 #末端区域 #区域“减法” 作为任务的公共异步函数cmdSub(ByVal num1作为整数,ByVal num2作为整数) 点心=num1-num2 Dim user=Context.user Dim channel=Context.channel wait channel.SendMessageAsync($“{user.antify}指定的两个数字之和为{sum}”) 端函数 #末端区域 #区域“倍增” 公共异步函数cmdMulti(ByVal num1为整数,ByVal num2为整数)作为任务 点心=num1*num2 Dim user=Context.user Dim channel=Context.channel wait channel.SendMessageAsync($“{user.antify}指定的两个数字之和为{sum}”) 端函数 #末端区域 #区域“分化” 公共异步函数cmdDivide(ByVal num1为整数,ByVal num2为整数)作为任务 点心=num1/num2 Dim user=Context.user Dim channel=Context.channel wait channel.SendMessageAsync($“{user.antify}指定的两个数字之和为{sum}”) 端函数 #末端区域 末级,discord,discord.net,Discord,Discord.net,我将如何创建一个命令,比如说“list”,它将自动发送一个包含命令列表的嵌入,而不必编写嵌入并自动填充?如果不能在嵌入中使用常规图像完成,则可以。我很确定它将使用for循环,但在那之后,我不知道如何使用它。在程序中的某个地方,您可能会遇到类似的问题 Dim集合作为新的ServiceCollection() collection.AddSingleton(DiscordSocketClient()) 或者将您的客户端添加到您的IserviceProvider 您ServiceProvider是用

我将如何创建一个命令,比如说“list”,它将自动发送一个包含命令列表的嵌入,而不必编写嵌入并自动填充?如果不能在嵌入中使用常规图像完成,则可以。我很确定它将使用for循环,但在那之后,我不知道如何使用它。

在程序中的某个地方,您可能会遇到类似的问题

Dim集合作为新的ServiceCollection()
collection.AddSingleton(DiscordSocketClient())
或者将您的客户端添加到您的
IserviceProvider

ServiceProvider
是用于依赖项注入的。要注入命令服务,您需要将其添加到
ServiceCollection

collection.AddSingleton(新CommandService())
要将其注入命令模块,只需向构造函数添加一个参数

公共类命令模块
继承ModuleBase(SocketCommandContext的)
作为CommandService的私有只读属性命令
Public Sub New(命令作为CommandService)
Me.Commands=命令
端接头
然后,您可以在该类中创建help命令,该类现在可以访问
CommandService


公共异步函数Help()作为任务
'创建嵌入生成器
'...
'您可以使用'CommandService.Modules'访问所有模块类`
对于每个moduleData,将其作为Commands.Modules中的ModuleInfo
Dim cmds As List(CommandInfo)=moduleData.Commands'这提供了此类中所有命令的列表
'您现在可以使用该命令列表执行某些操作
'例如,将每个字段添加到嵌入字段
下一个
端函数

您可以通过ModuleInfo和CommandInfo查看您可以访问的不同内容,
CommandService
提供您所需的所有信息。只需通过依赖项注入将它注入到您的模块中,并查看它的各种属性。你可以得到所有的模块,子模块,这些模块中的命令等。我不知道从哪里开始..我真的是一个新的当谈到编码,我不知道如何做注入或真正从哪里开始。谢谢你的帮助。我不是从头开始编写机器人的代码,我看了一段几年前的视频,所以不知道在哪里执行这些代码。查看了我的命令处理程序,它似乎是唯一一个提到服务提供者的地方,但无法将其全部整合在一起。谢谢你的帮助。
    <Group("math")>
Public Class cmd_math
    Inherits ModuleBase

#Region "Add"

    <Command("add")>
    Public Async Function cmdAdd(ByVal num1 As Integer, <Remainder> ByVal num2 As Integer) As Task

        Dim sum = num1 + num2
        Dim user = Context.User
        Dim channel = Context.Channel

        Await channel.SendMessageAsync($"{user.Mention} the sum of the two specified numbers are {sum}")

    End Function

#End Region

#Region "Subtract"

    <Command("sub")>
    Public Async Function cmdSub(ByVal num1 As Integer, <Remainder> ByVal num2 As Integer) As Task

        Dim sum = num1 - num2
        Dim user = Context.User
        Dim channel = Context.Channel

        Await channel.SendMessageAsync($"{user.Mention} the sum of the two specified numbers are {sum}")

    End Function

#End Region

#Region "Multiply"

    <Command("multi")>
    Public Async Function cmdMulti(ByVal num1 As Integer, <Remainder> ByVal num2 As Integer) As Task

        Dim sum = num1 * num2
        Dim user = Context.User
        Dim channel = Context.Channel

        Await channel.SendMessageAsync($"{user.Mention} the sum of the two specified numbers are {sum}")

    End Function

#End Region

#Region "Divide"

    <Command("divide")>
    Public Async Function cmdDivide(ByVal num1 As Integer, <Remainder> ByVal num2 As Integer) As Task

        Dim sum = num1 / num2
        Dim user = Context.User
        Dim channel = Context.Channel

        Await channel.SendMessageAsync($"{user.Mention} the sum of the two specified numbers are {sum}")

    End Function

#End Region

End Class