Created
March 26, 2019 15:49
-
-
Save iamnotacoder-djs/d9ed1dbe4d872884c7905b3ce42ebc14 to your computer and use it in GitHub Desktop.
NewProject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Discord = require('discord.js'); | |
const client = new Discord.Client(); | |
const config = require("./config.json"); | |
var messageId = ""; | |
client.login(config.token).catch((err) => { | |
// Если Node.JS поймал ошибку с текстом err просто выключаем скрипт | |
// process.exit(0); | |
}); | |
client.on("ready", () => { | |
// первый попавшийся канал от метода channels.first() вернул голосовой | |
// Давай лучше подключимся к нужному нам каналу напрямую!? | |
client.guilds.first().channels.get("539101775567781913").send("Hello World!"); | |
// client.guilds.find(i => i.id > 0) | |
client.channels.get("539101775567781913").send(`Нажми на эмодзи, чтобы получить/убрать роль!`) | |
.then((message) => { | |
message.react("1⃣"); | |
messageId = message.id; | |
}); | |
}); | |
client.on("message", (message) => { | |
// тут код при получении сообщения в переменную message | |
// Делаем так, чтобы наш бот не отвечал сам себе! | |
if (!message.author.bot) { | |
message.reply("Ответ"); // Напечатает: @author, Ответ | |
client.channels.get(message.channel.id).send("Ответ"); | |
client.channels.get(message.channel.id).send("*Курсив*"); | |
client.channels.get(message.channel.id).send("||Спойлер||"); | |
client.channels.get(message.channel.id).send("`Блок кода`"); | |
client.channels.get(message.channel.id).send("```Многострочный блок кода```"); | |
var answer = "Ответ"; | |
client.channels.get(message.channel.id).send(`-${answer}-`); // Печать: -Ответ- | |
client.channels.get(message.channel.id).send("-"+answer+"-"); // Печать: -Ответ- | |
client.channels.get(message.channel.id).send(`-\`${answer}\`-`); | |
client.channels.get(message.channel.id).send(`Новое emoji \`:hack:\`: ${client.emojis.find(emoji => emoji.name === "hack")}`); | |
// Не забываем про NEW Discord.RichEmbed() | |
const embed = new Discord.RichEmbed() | |
.setTitle("This is your title, it can hold 256 characters") | |
.setAuthor("Author Name", "https://i.imgur.com/lm8s41J.png") | |
/* | |
* Alternatively, use "#00AE86", [0, 174, 134] or an integer number. | |
*/ | |
.setColor(0x00AE86) | |
.setDescription("This is the main body of text, it can hold 2048 characters.") | |
.setFooter("This is the footer text, it can hold 2048 characters", "http://i.imgur.com/w1vhFSR.png") | |
.setImage("http://i.imgur.com/yVpymuV.png") | |
.setThumbnail("http://i.imgur.com/p2qNFag.png") | |
/* | |
* Takes a Date object, defaults to current date. | |
*/ | |
.setTimestamp() | |
.setURL("https://discord.js.org/#/docs/main/indev/class/RichEmbed") | |
.addField("This is a field title, it can hold 256 characters", | |
"This is a field value, it can hold 1024 characters.") | |
/* | |
* Inline fields may not display as inline if the thumbnail and/or image is too big. | |
*/ | |
.addField("Inline Field", "They can also be inline.", true) | |
/* | |
* Blank field, useful to create some space. | |
*/ | |
.addBlankField(true) | |
.addField("Inline Field 3", "You can have a maximum of 25 fields.", true); | |
client.channels.get(message.channel.id).send(embed); | |
client.channels.get(message.channel.id).send({ | |
embed: { | |
"title": "title ~~(did you know you can have markdown here too?)~~", | |
"description": "this supports [named links](https://discordapp.com) on top of the previously shown subset of markdown. ```\nyes, even code blocks```", | |
"url": "https://discordapp.com", | |
"color": 11750632, | |
"timestamp": "2019-03-26T13:33:29.282Z", | |
"footer": { | |
"icon_url": "https://cdn.discordapp.com/embed/avatars/0.png", | |
"text": "footer text" | |
}, | |
"thumbnail": { | |
"url": "https://cdn.discordapp.com/embed/avatars/0.png" | |
}, | |
"image": { | |
"url": "https://cdn.discordapp.com/embed/avatars/0.png" | |
}, | |
"author": { | |
"name": "author name", | |
"url": "https://discordapp.com", | |
"icon_url": "https://cdn.discordapp.com/embed/avatars/0.png" | |
}, | |
"fields": [ | |
{ | |
"name": "🤔", | |
"value": "some of these properties have certain limits..." | |
}, | |
{ | |
"name": "😱", | |
"value": "try exceeding some of them!" | |
}, | |
{ | |
"name": "🙄", | |
"value": "an informative error should show up, and this view will remain as-is until all issues are fixed" | |
}, | |
{ | |
"name": "<:thonkang:219069250692841473>", | |
"value": "these last two", | |
"inline": true | |
}, | |
{ | |
"name": "<:thonkang:219069250692841473>", | |
"value": "are inline fields", | |
"inline": true | |
} | |
] | |
} | |
}); | |
//https://image.ibb.co/hXHFqL/image.jpg | |
client.channels.get(message.channel.id).send("Картинка", {file: "https://image.ibb.co/hXHFqL/image.jpg"}); | |
} | |
}); | |
client.on("guildMemberAdd", (member) => { | |
// тут код при подключении нового участника на сервере в переменную member | |
}); | |
client.on("error", (error) => { | |
}); | |
client.on("warn", (warn) => { | |
}); | |
client.on("debug", (debug) => { | |
}); | |
const events = { | |
MESSAGE_REACTION_ADD: 'messageReactionAdd', | |
MESSAGE_REACTION_REMOVE: 'messageReactionRemove', | |
}; | |
client.on('raw', async event => { | |
if (!events.hasOwnProperty(event.t)) return; | |
const { d: data } = event; | |
const user = client.users.get(data.user_id); | |
const channel = client.channels.get(data.channel_id) || await user.createDM(); | |
if (channel.messages.has(data.message_id)) return; | |
const message = await channel.fetchMessage(data.message_id); | |
const emojiKey = (data.emoji.id) ? `${data.emoji.name}:${data.emoji.id}` : data.emoji.name; | |
const reaction = message.reactions.get(emojiKey); | |
client.emit(events[event.t], reaction, user); | |
}); | |
client.on('messageReactionAdd', (reaction, user) => { | |
let member = client.guilds.first().members.find(x => x.id == user.id); | |
if (member.roles.some(r => ["Вип"].includes(r.name))) { | |
if (reaction.message.id == messageId) { | |
if (reaction.emoji.name === "1⃣") { | |
let role = client.guilds.first().roles.find(x => x.name === "Цвет"); | |
member.addRole(role) | |
.catch((e)=>{}); | |
} | |
} | |
} | |
}) | |
client.on('messageReactionRemove', (reaction, user) => { | |
let member = client.guilds.first().members.find(x => x.id == user.id); | |
if (member.roles.some(r => ["Вип"].includes(r.name))) { | |
if (reaction.message.id == messageId) { | |
if (reaction.emoji.name === "1⃣") { | |
let role = client.guilds.first().roles.find(x => x.name === "Цвет"); | |
member.removeRole(role) | |
.catch((e)=>{}); | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment