c# - 如何在 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");
}
}
我也尝试过其他表情符号,但我仍然得到其他区域的响应
解决方案
以下应该工作。只需将表情符号复制/粘贴到双引号中即可。毕竟都是人物。
[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
变量作为表情符号本身通过
推荐阅读
- reactjs - 我正在尝试根据在地图功能中单击的按钮将 id 传递给内部组件
- javascript - 覆盖 p 标记中具有图像元素的段落
- python - 合并两个数据框并保留第一个 df 的额外行
- python - 有没有办法使用 Python 自己的类来模拟“bool”或“NoneType”类型的对象?
- pyspark - Pyspark:从 JSON 文件创建模式
- django - 如何使用 django rest 框架强制 URL?
- datetimepicker - 如何使用 Jquery Datetimepicker 禁用传递时间?
- java - 没有为类 org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor 找到序列化程序 一对一映射休眠
- smartgit - 我们如何在 Smartgit 客户端中创建合并请求?
- javascript - 当 Angular HostBinding 与指令赋值一起使用时会发生什么?