Add safeguards against missing roles and weird names
parent
3f9a07c51e
commit
fd80db33a3
6
index.js
6
index.js
|
@ -230,8 +230,10 @@ function getModmailChannel(user, allowCreate = true) {
|
||||||
} else {
|
} else {
|
||||||
if (! allowCreate) return Promise.resolve(null);
|
if (! allowCreate) return Promise.resolve(null);
|
||||||
|
|
||||||
|
const cleanName = user.username.replace(/[^a-zA-Z0-9]/ig, '').toLowerCase();
|
||||||
|
|
||||||
// If one is not found, create and cache it
|
// If one is not found, create and cache it
|
||||||
return modMailGuild.createChannel(`${user.username}-${user.discriminator}`)
|
return modMailGuild.createChannel(`${cleanName}-${user.discriminator}`)
|
||||||
.then(channel => {
|
.then(channel => {
|
||||||
// This is behind a timeout because Discord was telling me the channel didn't exist after creation even though it clearly did
|
// This is behind a timeout because Discord was telling me the channel didn't exist after creation even though it clearly did
|
||||||
// ¯\_(ツ)_/¯
|
// ¯\_(ツ)_/¯
|
||||||
|
@ -361,7 +363,7 @@ bot.registerCommand('reply', (msg, args) => {
|
||||||
saveAttachments(msg).then(() => {
|
saveAttachments(msg).then(() => {
|
||||||
bot.getDMChannel(channelInfo.userId).then(dmChannel => {
|
bot.getDMChannel(channelInfo.userId).then(dmChannel => {
|
||||||
const roleId = msg.member.roles[0];
|
const roleId = msg.member.roles[0];
|
||||||
const role = (roleId ? modMailGuild.roles.get(roleId).name : '');
|
const role = (roleId ? (modMailGuild.roles.get(roleId) || {}).name : '');
|
||||||
const roleStr = (role ? `(${role}) ` : '');
|
const roleStr = (role ? `(${role}) ` : '');
|
||||||
|
|
||||||
let argMsg = args.join(' ').trim();
|
let argMsg = args.join(' ').trim();
|
||||||
|
|
Loading…
Reference in New Issue