-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wiadomość na wzmiankę @everyone #4
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const Discord = require('discord.js'); | ||
const MentionsList = { | ||
EVERYONE: '@everyone', | ||
HERE: '@here' | ||
} | ||
const MENTION_PERMISSION = 'MENTION_EVERYONE'; | ||
const EMBED_COLOR = '#eb1540'; | ||
const EMBED_TITLE = 'Nie wołaj wszystkich!'; | ||
const EMBED_THUMBNAIL = 'https://i.imgur.com/nREiJww.png'; | ||
const EMBED_DESCRIPTION = '\nRozumiemy, że potrzebujesz pomocy, ale nie wszyscy chcą zostać o tym powiadomieni.\n Jest nas tutaj dużo i nie ma sensu, aby każdy dostał bezpośrednio taką informację.\n Nie trudno sobie wyobrazić jak irytujące byłoby, gdyby każdy wołał wszystkich do każdego tematu.\n Dlatego zadaj pytanie i po prostu poczekaj - jeśli ktoś będzie wiedział i mógł, to na pewno spróbuje odpowiedzieć.'; | ||
|
||
module.exports = { | ||
|
||
handler: function (message){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A czemu nie po prostu: module.exports = function mentionHandler(message) { ... } albo: function mentionHandler(message) { ... }
module.exports = mentionHandler; I wtedy użycie: const mentionHandler = require('./handlers/mentionHandler');
client.on('message', (message) => {
mentionHandler(message);
}); |
||
const pingEmbed = new Discord.MessageEmbed() | ||
.setColor(EMBED_COLOR) | ||
.setTitle(EMBED_TITLE) | ||
.setThumbnail(EMBED_THUMBNAIL) | ||
.setDescription(EMBED_DESCRIPTION); | ||
const mentions = message.content.includes(MentionsList.EVERYONE) || message.content.includes(MentionsList.HERE); | ||
try { | ||
const hasPermission = message.member.hasPermission(MENTION_PERMISSION); | ||
if (mentions && !hasPermission) { | ||
message.author.send(pingEmbed); | ||
} | ||
} catch(error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CodeKid0 upewnij się proszę, czy ten Moim zdaniem ten |
||
console.log(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skoro już jest tu ten There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jeśli chodzi o hasPermission w try...catch to jeśli to byłoby poza try...catch to bot, gdy ktoś napisze w wiadomości prywatnej wzmiankę się wysypie There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dlaczego się sypie? Jaki błąd tam jest rzucany? Z tego co kojarzę, to tam chyba jest błąd, że There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rzucany jest błąd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No to go zaifuj zamiast robić There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem w tym że discord.js niezbyt pozwala to zifować (albo poprostu jestem zbyt głupi by to zrobić :V) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W jakim sensie nie pozwala? Zamień: try{ //needed, if someone sends private message to bot, it crashes without try..catch
const hasPermission = message.member.hasPermission(MENTION_PERMISSION); na: const hasPermission = message.member.hasPermission && message.member.hasPermission(MENTION_PERMISSION); , albo: const hasPermission = typeof message.member.hasPermission === 'function' ?
message.member.hasPermission(MENTION_PERMISSION) : false; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moim zdaniem to nie zadziała, discord.js crashuje się jeśli spróbujesz uzyskać message.member.hasPermission bez try..catch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A próbowałeś? |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MentionsList
->mentionsList
, alboMENTIONS_LIST
(w sumie zamiast "list" bardziej pasuje "dict", bo to nie jest lista - ale to szczegół). Jeśli ten słownik jest traktowany jako stała, to można go też wrzucić wObject.freeze
.