Update Dm_Member.cs
adjusts the command to not require global intent only server, adds server id as a requirement adds a try catch around the sending part just in case of a random error ^+^
This commit is contained in:
parent
c8b5cb93a6
commit
3f85d1bae8
1 changed files with 28 additions and 8 deletions
|
|
@ -11,11 +11,11 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace BSB.Commands.DiscordAPI
|
namespace BSB.Commands.DiscordAPI
|
||||||
{
|
{
|
||||||
class Discord_Dm_Member : CoreCommand_3arg
|
class Discord_Dm_Member : CoreCommand_4arg
|
||||||
{
|
{
|
||||||
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Text" }; } }
|
public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number", "Text" }; } }
|
||||||
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Member id", "Message" }; } }
|
public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Server id", "Member id", "Message" }; } }
|
||||||
public override string Helpfile { get { return "Sends a message directly to the user \n This will fail if they are not friends or dont share a server!"; } }
|
public override string Helpfile { get { return "Sends a message directly to the user [They must be in the server]\n This command requires the SERVER MEMBERS INTENT found in discord app dev"; } }
|
||||||
public override bool CallFunction(string[] args)
|
public override bool CallFunction(string[] args)
|
||||||
{
|
{
|
||||||
if (base.CallFunction(args) == true)
|
if (base.CallFunction(args) == true)
|
||||||
|
|
@ -33,11 +33,31 @@ namespace BSB.Commands.DiscordAPI
|
||||||
protected async Task<bool> MessageMember(string[] args)
|
protected async Task<bool> MessageMember(string[] args)
|
||||||
{
|
{
|
||||||
DiscordSocketClient Discord = bot.getDiscordClient();
|
DiscordSocketClient Discord = bot.getDiscordClient();
|
||||||
if (ulong.TryParse(args[1], out ulong memberid) == true)
|
if (ulong.TryParse(args[1], out ulong serverid) == true)
|
||||||
{
|
{
|
||||||
SocketUser user = Discord.GetUser(memberid);
|
if (ulong.TryParse(args[2], out ulong memberid) == true)
|
||||||
await user.SendMessageAsync(args[2]);
|
{
|
||||||
return true;
|
try
|
||||||
|
{
|
||||||
|
SocketGuild server = Discord.GetGuild(serverid);
|
||||||
|
IEnumerable<IGuildUser> users = await server.GetUsersAsync().FlattenAsync().ConfigureAwait(true);
|
||||||
|
bool sent = false;
|
||||||
|
foreach(IGuildUser user in users)
|
||||||
|
{
|
||||||
|
if(user.Id == memberid)
|
||||||
|
{
|
||||||
|
sent = true;
|
||||||
|
await user.SendMessageAsync(args[3]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sent;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue