-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.cjs
47 lines (39 loc) · 1.27 KB
/
bot.cjs
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
const discord = require('discord.js');
const { AttachmentBuilder } = require('discord.js');
const config = require("./config.json");
const client = new discord.Client({
intents: [
discord.GatewayIntentBits.DirectMessages,
discord.GatewayIntentBits.MessageContent
],
partials: [
discord.Partials.DirectMessages,
discord.Partials.Message,
]
});
const token = config.token;
const channel_id = config.channel;
async function sendMessage(content){
const channel = await client.channels.fetch(channel_id);
channel.send(content);
}
async function fetchMessages(){
const channel = await client.channels.fetch(channel_id);
const messages = await channel.messages.fetch();
return messages;
}
async function sendTyping(){
const channel = await client.channels.fetch(channel_id);
await channel.sendTyping();
}
async function sendAttachment(file, filename){
const channel = await client.channels.fetch(channel_id);
const attachment = new AttachmentBuilder(file, { name: filename });
await channel.send({files: [attachment]});
}
client.login(token);
module.exports.sendMessage = sendMessage;
module.exports.fetchMessages = fetchMessages;
module.exports.Client = client;
module.exports.sendTyping = sendTyping;
module.exports.sendAttachment = sendAttachment;