Add set commands

This commit is contained in:
KillerBossOriginal 2023-08-13 13:56:37 +02:00
parent 98a87005b0
commit 16eaf7dfc5
3 changed files with 35 additions and 18 deletions

View file

@ -1,7 +1,8 @@
# 1.3.0 # 1.3.0
- Renamed `calculateIntents` to `intentsCalculator` - Renamed `calculateIntents` to `intentsCalculator`
- Add Docs in Guild Class - Add set slashcommands
- Add GuildDiscoverySplash - Add GuildDiscoverySplash
- Adding Docs in Guild Class
- Fix `guild_icon` - Fix `guild_icon`
- Fix `guild_splash` - Fix `guild_splash`
- Removed `base_image` - Removed `base_image`

View file

@ -42,6 +42,7 @@ class Client extends EventEmitter {
late ChannelManager channels; late ChannelManager channels;
bool ready = false; bool ready = false;
late User user; late User user;
var commands = {};
/// Create a new Client. /// Create a new Client.
/// [intents] Intents to enable for this connection, it's a multiple of two. /// [intents] Intents to enable for this connection, it's a multiple of two.
@ -94,23 +95,10 @@ class Client extends EventEmitter {
}); });
} }
Sender sender = Sender(token); late Sender sender;
var i = await sender.fetchGuilds(withCounts: true); late int n;
List<Guild> gg = []; ws.listen((event) async {
for (dynamic g in i) {
gg.add(Guild(sender, g));
}
channels = ChannelManager(sender, [], main: true);
sender.channels = channels;
guilds = GuildManager(sender, gg);
int n = i.length;
ws.listen((event) {
event = json.decode(event); event = json.decode(event);
switch (event["op"]) { switch (event["op"]) {
@ -130,6 +118,24 @@ class Client extends EventEmitter {
switch (eventName) { switch (eventName) {
case "READY": case "READY":
sender = Sender(token, event["d"]["user"]["id"]);
var i = await sender.fetchGuilds(withCounts: true);
List<Guild> gg = [];
for (dynamic g in i) {
gg.add(Guild(sender, g));
}
channels = ChannelManager(sender, [], main: true);
sender.channels = channels;
guilds = GuildManager(sender, gg);
n = i.length;
commands["set"] = sender.setCommands;
resumeGatewayURL = event["d"]["resume_gateway_url"]; resumeGatewayURL = event["d"]["resume_gateway_url"];
sessionID = event["d"]["session_id"]; sessionID = event["d"]["session_id"];
user = User(event["d"]["user"]); user = User(event["d"]["user"]);

View file

@ -36,10 +36,11 @@ Future<String> requestWebSocketURL() async {
class Sender { class Sender {
final String? _token; final String? _token;
final String id;
Map<String, String> headers = {}; Map<String, String> headers = {};
dynamic channels; dynamic channels;
Sender(this._token) { Sender(this._token, this.id) {
headers = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": "Bot $_token", "Authorization": "Bot $_token",
@ -86,6 +87,15 @@ class Sender {
res = json.decode(res.body); res = json.decode(res.body);
return res; return res;
} }
Future setCommands(List commands) async {
dynamic res = await http.put(Uri.parse("$apiURL/applications/$id/commands"), headers: headers, body: json.encode(commands));
if (res.statusCode != 200 || res.statusCode != 201) {
throw Exception("Error ${res.statusCode} receiving the member");
}
res = json.decode(res.body);
return res;
}
} }
Future interactionReply(String id, String token, Map<String, dynamic> content) async { Future interactionReply(String id, String token, Map<String, dynamic> content) async {