Animated emoji name doesn't display as i wanted - discord.js

So simple emoji command where it's supposed to display it's information like name, id, link and etc you get the idea. Works all fine with default emojis and custom server emojis but the moment its animated the name changes from
"<a:CS_Shrug:740861064257863690>" to just ":CS_Shrug:" i know this has something with discord displaying stuff but is there anyway to get around this? People asked for code:
let args = msg.content.slice(PREFIX.length).trim().split(/ +/); //slice message in an array
if (args[1]) { //if theres something mentioned
let newRawdata = fs.readFileSync('./emojis.json');
let newData = JSON.parse(newRawdata);
var findEmoji = Object.values(newData).find(object => object === args[1]) //just a file with all unicode emojis bc yes
if (args[1].startsWith("<:") && args[1].endsWith(">")) { //custom server emoji
//not important code
} else if (args[1].startsWith("<a:") && args[1].endsWith(">")){
let ForBots = args[1]
let namever1 = ForBots.replace('<a','')
let namever2 = namever1.replace('>','')
let namever3 = namever2.split(':')
let name = namever3[1]
let id = namever3[2]
var inforEmbed2 = new Discord.MessageEmbed()
.setColor('#2ab94c')
.setTitle('Emoji information')
.addFields(
{ name: 'Type', value: "`Animated server emoji`", inline: false },
{ name: 'Name', value: "`"+name+"`", inline: false },
{ name: 'ID', value: "`"+id+"`", inline: true },
{ name: 'For bots', value: "`"+args[1]+"`", inline: true }, //should display `<a:CS_Shrug:740861064257863690>` but instead `:CS_Shrug:`
{ name: 'Emoji link', value: "https://cdn.discordapp.com/emojis/"+id+".gif?/v=1", inline: false },
)
.setThumbnail('https://cdn.discordapp.com/emojis/'+id+'.gif?/v=1')
.setFooter("C.U.A.L - Bot| ;help", 'https://cdn.discordapp.com/attachments/864287060424785941/872600493082415124/Avatar_1.png')
msg.channel.send(inforEmbed2)
} else if (findEmoji) { //default emoji
//more none important code
} else msg.reply("donno wtf this is") // wasnt an emoji
} else msg.reply("Gotta give me something first")

Related

I want to check if someone has permission to be kicked, but the answer is wrong

I use msg.member.hasPermission('KICK_MEMBERS'), but even if the author of the message doesn't have this permission, the answer is true instead of false.
const Discord = require("discord.js");
const client = new Discord.Client();
channel = '858963360909099068';
module.exports ={
name: 'kick',
description: 'kick people',
execute(msg, args) {
let impostor = msg.mentions.members.first();
const mod = msg.author;
let botResponse;
if(msg.member.hasPermission('KICK_MEMBERS')){
console.log('true');
if(!impostor){
botResponse = 'You need to tag the person that you want to kick !';
impostor = 'Not specified';
}
else{
botResponse = `${impostor} was kicked !`;
impostor.kick();
}
}
else{
console.log('false');
botResponse = 'You are not able to kick people !';
}
let embed = new Discord.MessageEmbed()
.setColor('#f9ae0e')
.setTitle('Kick')
.setDescription(botResponse)
.addFields(
{ name: "Impostor", value: impostor},
{ name: "Member", value: mod}
);
msg.channel.send(embed);
}
}
This is the error:
TypeError: msg.member.hasPermission is not a function
I can't see what's wrong here, can you help me solve it?
You should change msg.member.hasPermission('PERM') to msg.member.permissions.has('PERM')

How to put emoji icon into embed thumbnail when emojiCreated

When someone adds an emoji to the server, the bot will log it. I'm trying to make it where it will but the emoji in the thumbnail of the log embed. Whenever it trys to log, I get the error..
[15:55:28] [UTC June:10:2021] [ERROR] (node:11176) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body embed.thumbnail.url: Scheme "undefined" is not supported. Scheme must be one of ('http', 'https'). embeds[0].thumbnail.url: Scheme "undefined" is not supported. Scheme must be one of ('http', 'https').
I'm guessing that the code for the thumbnail is returned undefined and you can't put that into a thumbnail. My code is
const Discord = require("discord.js")
exports.run = async(client) => {
client.on("emojiCreate", function(emoji){
console.log(emoji)
const Embedf = new Discord.MessageEmbed()
.setColor("#1CDEA3")
.setTitle('New Emoji Created')
.addFields(
{ name: 'Emoji Name:', value: emoji.name, inline: false },
{ name: 'Emoji ID:', value: emoji.id, inline: false },
{ name: 'Nitro Emote?', value: emoji.animated, inline: false })
.setThumbnail(`${emoji.icon}`)
.setFooter(`${emoji.guild.name}`)
.setTimestamp()
client.channels.cache.find(channel => channel.id == "851987273837969408").send(Embedf)
})
}
How can I fix this? Thanks
A GuildEmoji does not have an icon property.
You may have meant to use the url property.
const Embedf = new Discord.MessageEmbed()
.setColor("#1CDEA3")
.setTitle('New Emoji Created')
.addFields(
{ name: 'Emoji Name:', value: emoji.name, inline: false },
{ name: 'Emoji ID:', value: emoji.id, inline: false },
{ name: 'Nitro Emote?', value: emoji.animated, inline: false })
.setThumbnail(emoji.url) // use URL instead of icon
.setFooter(emoji.guild.name)
.setTimestamp()

Why does messageUpdate and messageDelete get triggered multiple times?

I'm trying to make logs for my server, so when someone sends, deletes or edits a message, the bot will send an embed message in a specific channel with all the information. For some reason, the messageUpdate and messagedDelete events are triggered multiple times, and I can't understand why. I have tried everything, but nothing works. Why does this happen and how can I fix it?
I have the logs for each thing (sent, edited, deleted) in individual files, by the way. In my main file, this is the code I have for the messageUpdate:
bot.on('messageUpdate', (oldMessage, newMessage) => {
if (oldMessage.author.id === bot.user.id) return;
if(oldMessage.content === newMessage.content) return;
bot.events.get('editlogs').execute(oldMessage, newMessage);
})
This is my code for the edit logs:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login(process.env.TOKEN);
module.exports = {
name: 'editlogs',
description: 'logs messages that were edited.',
category: 'logs',
execute(oldMessage, newMessage){
const logsChannel = bot.channels.cache.get("743142195594526822")
const logEmbed = new Discord.MessageEmbed()
.setColor('#ffa600')
.setTitle('Message Edited')
.setAuthor(oldMessage.author.tag, oldMessage.author.avatarURL())
.setThumbnail(oldMessage.author.avatarURL())
.addFields(
{ name: 'Old Message', value: oldMessage.content},
{ name: 'New Message', value: newMessage.content},
{ name: 'Channel', value: oldMessage.channel.toString(), inline: true },
{ name: 'Author', value: oldMessage.author, inline: true },
{ name: 'Author ID', value: oldMessage.author.id},
{ name: 'Message ID', value: oldMessage.id},
{ name: 'Message', value: '[Jump To Message](' + oldMessage.url + ')'},
)
.setTimestamp()
.setFooter('Edited in ' + oldMessage.guild.toString(), oldMessage.guild.iconURL());
logsChannel.send(logEmbed);
}}

How to get old and new value of dynamically generated checkbox column in agGrid

I am using agGrid where the columns are dynamically created. My objective is to get the old value and new value after checking the checkboxes. I try to use "onCellValueChanged" but it didnt work. If I use "onCellClicked" then I am not getting Old Value and New Value.
For your understanding I want to mean by Old Value and New Value that if user checked then Old Value is false and New Value is true.
HTML
<ag-grid-angular class="ag-theme-balham" [gridOptions]="siteJobDeptGridOptions"
[rowData]="siteJobDeptRowData" [columnDefs]="siteJobDeptColDef" [paginationPageSize]=10 [domLayout]="domLayout"
(gridReady)="onGridReady($event)">
</ag-grid-angular>
TS File
export class SiteJobDeptConfigComponent implements OnInit {
ngOnInit() {
this.domLayout = "autoHeight";
this.getAllSiteJobConfig();
this.generateColumns();
}
onGridReady(params: any) {
params.api.sizeColumnsToFit();
params.api.resetRowHeights();
}
generateColumns()
{
let deptColDef = [];
let colSiteJob = {
field: 'SiteJobName', headerName: 'Site Job Name',resizable: true,
sortable: true, filter: true, editable: false,
}
this.siteJobDeptCommonService.getEntityData('getpublisheddepts')
.subscribe((rowData) => {
deptColDef.push(colSiteJob);
for(let dept of rowData)
{
deptColDef.push({
field: dept.DeptName, headerName: dept.DeptName, width:100,resizable: true,
cellClass: 'no-border',
cellRenderer : params => {
var input = document.createElement('input');
input.type="checkbox";
input.checked=params.data[dept.DeptName];
return input;
},
onCellValueChanged: this.siteDeptCellValueChanged.bind(this),
})
}
this.siteJobDeptColDef = deptColDef;
},
(error) => { alert(error) });
}
siteDeptCellValueChanged(dataCol: any) {
let checkedOldValue = "Old Check Value - " + dataCol.oldValue;
let checkedNewValue = "New Check Value - " + dataCol.newValue;
}
getAllSiteJobConfig()
{
let siteJobRowData = [];
this.siteJobDeptCommonService.getEntityData('getallsitedeptjob')
.subscribe((rowData) => {
for(let siteJobDetail of rowData)
{
for(let deptAllow of siteJobDetail.DeptAllow)
{
tempArray[deptAllow["DeptName"]] = deptAllow["IsAllow"];
}
siteJobRowData.push(tempArray);
}
this.siteJobDeptRowData = siteJobRowData;
},
(error) => { alert(error) });
}
}
The grid looks like below:-
Can you please help me how to get Old Data and New Data value from checkbox that is dynamically generated?
It should be "cellValueChanged" not "onCellValueChanged" in the column definition creation.
You can find here.
When you declare your method in the params object, there are oldValue and newValue properties that give the result that you are looking for:
onCellValueChanged: function(params) {
console.log(params.oldValue);
console.log(params.newValue)
}

How to write structured data with JSON writer?

How can I include hasOne associated model data in the JSON POST?
Structured data is required by my web API in the form of:
{
id: 1234,
name: 'Aaron Smith',
address: {
address1: '1925 Isaac Newton Sq',
address2: 'Suite 300',
city: 'Reston',
state: 'VA',
zip: 20190
}
}
#nonino
I think I know how to do it but I am also having a similar problem. I can't actually get my associations to give me the associated data. Anyway from what I have scrounged on the internet make a custom writer like this or just in the default writers getRecordData: function(record,operation)
Here is my custom writer
Ext.define('Wakanda.writer', {
extend: 'Ext.data.writer.Json',
// alternateClassName: 'SimplyFundraising.data.WakandaWriter',
alias: 'writer.wakanda',
writeAllFields: false,
getRecordData: function(record,operation) {
debugger;
Ext.apply(record.data,record.getAssociatedData());
debugger;
var isPhantom = record.phantom === true,
writeAll = this.writeAllFields || isPhantom,
nameProperty = this.nameProperty,
fields = record.fields,
data = {},
changes,
name,
field,
key;
if (writeAll) {
// console.log("getRecordData1", this, arguments);
fields.each(function(field){
if (field.persist) {
debugger;
name = field[nameProperty] || field.name;
data[name] = record.get(field.name);
} else {
}
});
} else {
changes = record.getChanges();
debugger;
// console.log("getRecordData2", this, arguments, changes);
for (key in changes) {
if (changes.hasOwnProperty(key)) {
field = fields.get(key);
name = field[nameProperty] || field.name;
data[name] = changes[key];
}
}
if (!isPhantom) {
debugger;
data[record.idProperty] = record.getId();
if(operation.action !== 'destroy'){
data[record.stampProperty] = record.get(record.stampProperty);
}
}
}
return {'__ENTITIES': [data]};
}
});
The key I think is in the getRecordData where I have a statement Ext.apply(record.data,record.getAssociatedData()); If record.getAssociatedData does indeed return your data then the Ext.apply statement will merge your current record.data with your record.getAssociatedData into 1 json file. At least this is what I hope happens. Can't test until I get my associations setup correctly.
Hope this helps,
Dan
getRecordData: function(record,operation) {
debugger;
Ext.apply(record.data,record.getAssociatedData());
debugger;

Resources