Add set commands
This commit is contained in:
parent
98a87005b0
commit
16eaf7dfc5
3 changed files with 35 additions and 18 deletions
|
@ -1,7 +1,8 @@
|
|||
# 1.3.0
|
||||
- Renamed `calculateIntents` to `intentsCalculator`
|
||||
- Add Docs in Guild Class
|
||||
- Add set slashcommands
|
||||
- Add GuildDiscoverySplash
|
||||
- Adding Docs in Guild Class
|
||||
- Fix `guild_icon`
|
||||
- Fix `guild_splash`
|
||||
- Removed `base_image`
|
||||
|
|
|
@ -42,6 +42,7 @@ class Client extends EventEmitter {
|
|||
late ChannelManager channels;
|
||||
bool ready = false;
|
||||
late User user;
|
||||
var commands = {};
|
||||
|
||||
/// Create a new Client.
|
||||
/// [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);
|
||||
var i = await sender.fetchGuilds(withCounts: true);
|
||||
late Sender sender;
|
||||
late int n;
|
||||
|
||||
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);
|
||||
|
||||
int n = i.length;
|
||||
|
||||
ws.listen((event) {
|
||||
ws.listen((event) async {
|
||||
event = json.decode(event);
|
||||
|
||||
switch (event["op"]) {
|
||||
|
@ -130,6 +118,24 @@ class Client extends EventEmitter {
|
|||
|
||||
switch (eventName) {
|
||||
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"];
|
||||
sessionID = event["d"]["session_id"];
|
||||
user = User(event["d"]["user"]);
|
||||
|
|
|
@ -36,10 +36,11 @@ Future<String> requestWebSocketURL() async {
|
|||
|
||||
class Sender {
|
||||
final String? _token;
|
||||
final String id;
|
||||
Map<String, String> headers = {};
|
||||
dynamic channels;
|
||||
|
||||
Sender(this._token) {
|
||||
Sender(this._token, this.id) {
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bot $_token",
|
||||
|
@ -86,6 +87,15 @@ class Sender {
|
|||
res = json.decode(res.body);
|
||||
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 {
|
||||
|
|
Reference in a new issue