This website works better with JavaScript.
Home
Issues
Pull Requests
Milestones
AI流水线
Repositories
Datasets
Forum
实训
竞赛
大数据
Register
Sign In
youys
/
Discord.Net
Not watched
Unwatch
Watch all
Watch but not notify
1
Star
0
Fork
0
Code
Releases
34
Wiki
Activity
Issues
0
Pull Requests
0
Datasets
Model
Cloudbrain
Browse Source
Fix numeric type check for options
pull/1923/head
quin lynch
3 years ago
parent
ef4aa62363
commit
8439019f92
2 changed files
with
34 additions
and
2 deletions
Split View
Diff Options
Show Stats
Download Patch File
Download Diff File
+2
-2
src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs
+32
-0
src/Discord.Net.Core/Extensions/ObjectExtensions.cs
+ 2
- 2
src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs
View File
@@ -34,8 +34,8 @@ namespace Discord
get => _value;
set
{
if (value != null && value is not
int && value is not string
)
throw new ArgumentException("The value of a choice must be a string or
int
!");
if (value != null && value is not
string && !value.IsNumericType()
)
throw new ArgumentException("The value of a choice must be a string or
a numeric type
!");
_value = value;
}
}
+ 32
- 0
src/Discord.Net.Core/Extensions/ObjectExtensions.cs
View File
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Discord
{
internal static class ObjectExtensions
{
public static bool IsNumericType(this object o)
{
switch (Type.GetTypeCode(o.GetType()))
{
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Decimal:
case TypeCode.Double:
case TypeCode.Single:
return true;
default:
return false;
}
}
}
}
Write
Preview
Loading…
Cancel
Save