-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
108 lines (78 loc) · 2.62 KB
/
Copy pathbot.js
File metadata and controls
108 lines (78 loc) · 2.62 KB
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
99
100
101
102
103
104
105
106
107
108
const djs = require('discord.js');
const djsV = require('@discordjs/voice');
const fs = require("fs")
const { Readable } = require('stream');
const prefix = "!";
const keys = require("./token");
const clientId = keys.clientId;
const token = keys.token;
const guildId = keys.guildId;
const client = new djs.Client({ intents: [
djs.GatewayIntentBits.Guilds,
djs.GatewayIntentBits.GuildMessages,
djs.GatewayIntentBits.MessageContent,
djs.GatewayIntentBits.GuildVoiceStates
] });
client.on(djs.Events.ClientReady, (client) => {
console.log(`Logged in as ${client.user.tag}`);
client.user.setActivity({
type: djs.ActivityType.Custom,
name: "custom",
state: "u & me > 100 miles 🕺"
})
});
const msgCmds = require('./textMsgCmds');
const slashCmds = require('./slashCmds');
let commands = [];
for ({name, description, options} of Object.values(slashCmds)){
const cmd = {name, description};
if (options) {
cmd.options = options;
}
commands.push(cmd);
console.log(`added cmd ${name}`)
}
const rest = new djs.REST({ version: '10'}).setToken(token);
async function syncCommands() {
try {
console.log(`Refreshing app cmds.`);
const data = await rest.put(djs.Routes.applicationGuildCommands(clientId,guildId), { body: commands} )
console.log(`"cmd refresh success" ${data.length}`);
} catch (err){
console.error(err);
}
}
syncCommands();
client.on(djs.Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand() || !interaction.inGuild()) return;
slashCmds[interaction.commandName].do(interaction);
})
client.on(djs.Events.MessageContent, async (msg)=>{
console.log(msg);
})
const player = djsV.createAudioPlayer();
client.on(djs.Events.MessageCreate, async msg => {
if (msg.author.bot) return;
if (msg.content[0] == prefix){
const cmdObj = msgCmds[msg.content.substring(1,)];
if (cmdObj) {
cmdObj.do(msg);
} else {
msg.reply("?")
}
}
else if (djsV.getVoiceConnection(msg.guildId)){
const text = msg.content;
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const stream = Readable.from(buffer);
const resource = djsV.createAudioResource(stream, {
inputType: djsV.StreamType.Arbitrary,
});
const connection = djsV.getVoiceConnection(msg.guildId);
connection.subscribe(player);
player.play(resource);
await msg.reply("voiced message: "+text)
}
})
client.login(token);