How Find Emojis By Name In Discord.js

后端 未结 4 1090
渐次进展
渐次进展 2021-01-24 08:01

So I have been utterly frustrated these past few days because I have not been able to find a single resource online which properly documents how to find emojis when writing a di

相关标签:
4条回答
  • 2021-01-24 08:38

    I've made changes to your code.

    I hope it'll help you!

    const Discord = require("discord.js");
    const client = new Discord.Client();
    
    
    client.on('ready', () => {
    	console.log('ready');
    });
    
    
    client.on('message', message => {
    	var bean = message.guild.emojis.find(emoji => emoji.name == 'bean');
    	// By guild id 
    	if(message.guild.id == 'your guild id') {
    	if(bean) {
        		if(message.content.startsWith("<:bean:" + bean.id + ">")) {
        			message.react(bean.id);
        		}
        	}
    }
    });

    0 讨论(0)
  • 2021-01-24 08:43

    I never used discord.js so I may be completely wrong

    from the warning I'd say you need to do something like

    client.emojis.find(emoji => emoji.name === "bean") 
    

    Plus after looking at the Discord.js Doc it seems to be the way to go. BUT the docs never say anything about client.emojis.find("name", "bean") being wrong

    0 讨论(0)
  • 2021-01-24 08:49

    Please check out the switching to v12 discord.js guide

    v12 introduces the concept of managers, you will no longer be able to directly use collection methods such as Collection#get on data structures like Client#users. You will now have to directly ask for cache on a manager before trying to use collection methods. Any method that is called directly on a manager will call the API, such as GuildMemberManager#fetch and MessageManager#delete.

    In this specific situation, you need to add the cache object to your expression:

    var bean = message.guild.emojis.cache?.find(emoji => emoji.name == 'bean');
    
    0 讨论(0)
  • 2021-01-24 08:49

    In case anyone like me finds this while looking for an answer, in v12 you will have to add cache in, making it look like this:

    var bean = message.guild.emojis.cache.find(emoji => emoji.name == 'bean');
    

    rather than:

    var bean = message.guild.emojis.find(emoji => emoji.name == 'bean');

    0 讨论(0)
提交回复
热议问题