如何在循环中替换机器人的消息? DSharp 按钮

问题描述 投票:0回答:1

我想在一个文本经常变化的机器人中写一些游戏。但是我不明白如果不使用声明的新变量该怎么做 请帮助形成一个永久按钮跳转,但没有硬代码

[Command("test_button")]
        public async Task But(CommandContext ctx)
        {
            var button = await ctx.RespondAsync(m => m.WithContent("blya")
            .AddComponents(new DiscordButtonComponent(ButtonStyle.Primary, "button-one", "button")));

            var people = new string[] { "textAAA", "textBBB", "textCCC" };

            var result = await button.WaitForButtonAsync();

            await result.Result.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate).ConfigureAwait(false);
            await button.ModifyAsync(people[0]).ConfigureAwait(false);

            // how to fix it?
            var result2 = await button.WaitForButtonAsync();

            await result2.Result.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate).ConfigureAwait(false);
            await button.ModifyAsync(people[1]).ConfigureAwait(false);

            var result3 = await button.WaitForButtonAsync();

            await result3.Result.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate).ConfigureAwait(false);
            await button.ModifyAsync(people[2]).ConfigureAwait(false);

我认为这可以通过委托或 => 来完成,但我还是编程新手,所以我不知道该怎么做 我将非常感谢您的建议或提示

c# loops button bots
1个回答
0
投票

我只需要一个循环“for”,我昏昏沉沉

for (int i = 0; i < 3; i++)
{
    var result = await one.WaitForButtonAsync();
    await result.Result.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate).ConfigureAwait(false);
    await one.ModifyAsync(text[i]).ConfigureAwait(false); 
}
© www.soinside.com 2019 - 2024. All rights reserved.