Reputation: 71
I have a command that is repeating a message, and replacing the first 2 parts of the message with nothing, which are 'c!fquote @user' in the actual message. This works on any server with few members, but at some threshhold (im not sure when) discord changes tags to a format using . When pasted into chat, it does tag the person but my bot reads off the actual tag.
let user = message.mentions.users.first()
let saymsgchecked = saymsg.replace("c!fquote " + user," ")
if(saymsgchecked.endsWith(" ")){
message.channel.send(helpquoteEmbed)
}
else{
const quoteEmbed = new Discord.RichEmbed()
.setColor('#00abff')
.setAuthor(user.username + " said:", user.avatarURL, '')
.setTitle(saymsg.replace("c!fquote " + user,""))
.setTimestamp()
message.channel.send(quoteEmbed)
message.delete(1)
}
So the main part here; "(saymsg.replace("c!fquote " + user,""))", is replacing these two in the message. User, in small servers, reads as @username. Works good! But in larger servers, it reads as "< !@659818749185728 >" (random numbers for example, without the spaces) but the message contains @username, not that string of numbers, so it doesnt replace it. How can I handle this formatting? I've thrown the bot into 2 servers with 200+ members and into 3 random new ones with under 5 users, and it does the same exact thing in the large servers but works perfectly in small servers.
So basically what I'm looking for is, either: How can I make it stop reading the usertag as a number string in large servers? or; How can I change the "+ user" into something that includes both the actual tag text (eg. @username) and the string (eg. < !@4598572198454523>)
Upvotes: 0
Views: 1670
Reputation: 144
I think the best way to do this is once you have the user, use their id.
// don't use this if you need the user object later, and not just the id.
const { id } = message.mentions.members.first();
// to mention that person as the bot
message.channel.send(`Hey there, <@${id}>`);
There shouldn't be a problem with this, but if there is feel free to comment below and let me know what is happening if the problem changes.
Upvotes: 0
Reputation: 71
An update:
I've done a double filter for the ID with:
setTitle(saymsg.replace("c!fquote <@!" + userlarge.id + "> ",""))
it works, but is an ineffective solution because i'm creating a duplicate once it checks if the server has over N members. I have it set at, if the server has over 100, use this format instead of the tag format, because 100 is a nice round number. But I don't know exactly when the formatting changes to <@!>, it could be 250 or maybe even 23. I don't know, so I'm still looking for an alternate solution to this.
Upvotes: 1
Reputation: 500
The mesaage contains <@ID>
or <@!ID
, you have to filter for it.
The display of the message might be different.
Moreover you can take a look at https://discord.js.org and search for mention
to get the mentions of a message very easy.
Upvotes: 1