首页 > 解决方案 > 如何在 C# if 语句中使用 Discord 表情符号

问题描述

我正在为我的机器人制作商店命令,其中包含栗子、戒指、橘子、甜甜圈和挑选表情符号作为测试运行。当我尝试输入 :chestnut: emoji 作为要购买的商品时,它会将其保存为“item”,但它似乎与 if 语句中的“:chestnut:”不同

[Command("buy")]
public async Task Buy(string item)
{
    if (item == ":chestnut:" || item == ":ring:" || item == ":tangerine:" || item == ":doughnut:" || item == ":pick:")
    {
        await ReplyAsync($"{item} purchased!");
    }
    else
    {
        await ReplyAsync("Please enter of of the correct item emojis in order to purchase");
    }
}

我也尝试过其他表情符号,但我仍然得到其他区域的响应

标签: c#discorddiscord.net

解决方案


以下应该工作。只需将表情符号复制/粘贴到双引号中即可。毕竟都是人物。

[Command("buy")]
public async Task Buy(string item)
{
    if (item == "" || item == "" || item == "" || item == "" || item == "⛏")
    {
        await ReplyAsync($"{item} purchased!");
    }
    else
    {
        await ReplyAsync("Please enter of of the correct item emojis in order to 
        purchase");
    }
}

此解决方案假定item变量作为表情符号本身通过


推荐阅读