-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
98 lines (83 loc) · 2.71 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require("dotenv").config();
const {
Client,
GuildMember,
GatewayIntentBits,
Events,
} = require("discord.js");
const {
joinVoiceChannel,
getVoiceConnection,
VoiceConnectionStatus,
AudioPlayerStatus,
generateDependencyReport,
StreamType,
createAudioPlayer,
createAudioResource,
} = require("@discordjs/voice");
const { commandControl } = require("./app/controller/command-control");
const { messageControl } = require("./app/controller/message-control");
let clientVoice = require("./app/controller/voice");
global.client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
],
});
let clientReady = false;
client.on("ready", async () => {
client.user.setStatus("online");
console.log(`Logged in as ${client.user.tag}!`);
clientReady = true;
});
client.on("interactionCreate", async (interaction) => {
try {
// const User = await client.users.fetch(interaction.user);
// const guild = await client.guilds.cache.get(interaction.guildId);
// const member = await guild.members.fetch(User.id);
// const currentVoiceChannel = member.voice.channel?.id
// ? await client.channels.fetch(member.voice.channel.id)
// : null;
const currentVoiceChannel = await getCurrentVoiceChannel(
interaction,
interaction.user
);
await commandControl(interaction, currentVoiceChannel);
} catch (e) {
console.log(e);
}
});
client.on("messageCreate", async (msg) => {
try {
if (msg.author.id == process.env.CLIENTID) return null;
// const User = await client.users.fetch(msg.author);
// const guild = await client.guilds.cache.get(msg.guildId);
// const member = await guild.members.fetch(User.id);
// const currentVoiceChannel = member.voice.channel?.id
// ? await client.channels.fetch(member.voice.channel.id)
// : null;
const currentVoiceChannel = await getCurrentVoiceChannel(msg, msg.author);
const result = await messageControl(msg, currentVoiceChannel);
result != null ? msg.reply(result) : null;
} catch (e) {
console.log(e);
}
});
client.login(process.env.TOKEN);
const getCurrentVoiceChannel = async (connection, user) => {
const User = await client.users.fetch(user);
const guild = await client.guilds.cache.get(connection.guildId);
const member = await guild.members.fetch(User.id);
const currentVoiceChannel = member.voice.channel?.id
? await client.channels.fetch(member.voice.channel.id)
: null;
return currentVoiceChannel;
};
// var myInt = setInterval(function () {
// if (clientReady) {
// console.log(client.user);
// }
// }, 1000);