Good day,
I missed something in telethondocumentation. All is clear with files, messages, document, but i cannot find, how to send emoji to other user. When I send emoji code like ;-) it sends it as raw message. If it is equals to send file, please help me to find list of emoji id to put into file variable. Official documentation provides functions below, it is not clear.
GetEmojiKeywordsDifferenceRequest
GetEmojiKeywordsLanguagesRequest
GetEmojiKeywordsRequest
GetEmojiURLRequest
Please hint me with it :)
Emoji are just strings, like any other in Python. The ";-)" replacement for "๐" in official clients is done on the client side, not the server.
You should be able to paste the emoji directly into your code, or if your editor does not support it, use a Python unicode escape:
client.send_message(chat, '๐')
client.send_message(chat, '\U0001F609')
If you prefer to use text replacements in your code, install the emoji package:
import emoji
client.send_message(chat, emoji.emojize(':wink:'))
(Please note I have not tried the emoji module myself, see their documentation for available replacements.)
Related
I'm trying to encode text of biography for Instagram change biography on profile and it doesnt accept my biography.
I used:
let bio = "111X#%(!#)!$(*!Gram)"
let biography = encodeURIComponent(bio)
and it failing. Need help please
Java equivalent to JavaScript's encodeURIComponent that produces identical output?
I need this but for NodeJS, so it generate same encoding as Java one.
There are some distinctions between Java's URI encoding and the JS encodeURIComponent functions. Spaces will translate to + in Java but they will translate to %20 in Javascript. The JS function uses UTF-8 by default, but Java could be using a different format for encoding (depending on your code editor). Take a look at this stack overflow post for more information: https://stackoverflow.com/a/25298843/9571755
Hope that helps and happy coding :)
I've made a discord bot using python and I'd like to add a bug reporting command and some other commands so I was wondering how I could do this. For example User types: /report_bug and the bot responds: describe the bug. and then the User types in the bug. How could this be possible?
Here's a small snippet of the response code:
def handle_response(message) -> str:
p_message = message.lower()
if p_message == 'report_bug':
return 'Describe the bug'
#so here's where I'd like to take user input
You can't do anything after returning but assuming you just want to know how to get input:
Just add it as an argument to your command instead of making the bot ask for additional input afterwards. This makes the most sense, is the most user-friendly, and is the least pain to implement.
Use wait_for with a check.
Show a Modal where they can type whatever they want to.
Official examples for slash commands (with arguments): https://github.com/Rapptz/discord.py/blob/master/examples/app_commands/basic.py
Official example for a Modal: https://github.com/Rapptz/discord.py/blob/master/examples/modals/basic.py
Constraints of the problem:
My python bot needs to iterate through a list of messages to find reactions (I have that implemented and working), so I cannot use "on_reaction" or async's related to reactions on the final implementation
I don't want to use custom classes (I don't know how to convert my current code to be compatible and don't want to bother). I believe that means payload is out of the question?
What I have done:
I began with this tutorial: https://www.youtube.com/watch?v=iRHBGZWOwVo&list=PL6gx4Cwl9DGAHdJdtEl0-XiRfPRAvpbSz&index=6
I will summarize the relevant parts of the video, so you don't have to watch. I wrote code that uses aynscs to print the reaction emojis to the shell. I then copied and pasted the images into a comment in my code, and from there into the code where relevant. This worked great for 6 of the 8 emojis I am interested in detecting.
Detecting looks like such (for the working 6 of 8)
if str(reaction.emoji) == '๐':
The problem:
I used the same technique for all 8 emojis, but my bot isn't detecting two different ones, despite them being present in the search messages. These two emojis are :heart: and :hearts: by Discord's syntax. How can I get these emojis to be detected? I've tried every combination of reaction.emojis.name and str(reaction.emojis.name) imaginable.
I found this - and used the "copy" function and pasted it into the code. Worked like a charm. The discord :hearts: is just the Heart Suit emoji.
https://emojipedia.org/red-heart/
So I made an enlarge command that enlarges custom emojis in servers, and it works but I want to get it to where it does default emojis as well. I donโt know how to do default ones, so can someone help?
Hereโs the current code:
#commands.command()
async def enlarge(self, ctx, emoji: typing.Union[discord.Emoji, discord.PartialEmoji, str]):
if type(emoji) is str:
return await ctx.reply('Please enter an emoji to enlarge!')
else:
await ctx.send(emoji.url)
The default discord emoji are just unicode characters.
This is also the reason why custom emoji return an Emoji-Object, while default ones only return a string or single character. What you want to do is convert the unicode emoji characters to an image that represents them.
For this, you need some source of those images.
As described in this github gist, discord uses Twemoji as their default emoji source.
In the Twemoji-Github, they mention MaxCDN as their CDN supporter.
While this is meant to primarily address Javascript-Developers who want to use the Twemoji-scripts on their websites, it also provides the emoji icons.
It is possible to fetch those icons via
https://twemoji.maxcdn.com/v/latest/EMOJI_SIZE/EMOJI_ID.png In this url, you need to replace EMOJI_SIZE by the image size (72x72 is currently the only one available, but it should fit your needs quite well).
You also need to determine your emojis โidโ/Unicode codepoint (denoted by EMOJI_ID in above link), an integer in hexadecimal notation which represents your emoji character.
If emoji stores your character, you can obtain this integer using
emoji_id = ord(emoji)
Putting it all together, your command could look like this:
#bot.command()
async def enlarge(ctx, emoji: typing.Union[discord.Emoji, discord.PartialEmoji, str]):
if type(emoji) is str:
emoji_id = ord(emoji[0]) # Emoji is a string, we will use the first character
await ctx.send(f'https://twemoji.maxcdn.com/v/latest/72x72/{emoji_id:x}.png')
else:
await ctx.send(emoji.url)
Note that I use Python's f-Strings for formatting which is supported since Python 3.6.
If you are running an older version, you have to use another way of formatting.
Keep in mind that you will need the hexadecimal representation in your url.
If you don't want to use MaxCDN to serve the images, you could also download them at the Twemoji Github and store them locally.
Inside discord, it is also possible to right-click an emoji and get a discordcdn-link, but I wasn't able to construct those links from a given emoji.
Maybe someone else knows how to do this in order to avoid external services like MaxCDN.
I am learning how to develop Skills with Alexa. I followed a Lynda course to build the My Calculator skill, however ran into a problem where the numbers and results are not returned. I double checked my code, and tried it on Echoism.io, and same problem.
Per the attached, the numbers are recorded in the JSON input, however are not returned in the speechText or displayText?
What is the missing piece of code? Thanks.
Node.js code
Alexa console JSON Input
Welcome Roy! Couple things. In the future just put your code right here on the page so that it becomes searchable and we can see the exact characters you are using.
By looking at the images it looks like to me the following might be your use of template literals. Super common mistake.
So to use template literals you need use the back tick (`) instead of the single quote (')
It looks like it is that you currently have
speechText = 'The result of ${firstNumber} plus ${secondNumber} is ${result}';
and what you want is
speechText = `The result of ${firstNumber} plus ${secondNumber} is ${result}`;
Here is another good resources:
How to interpolate variables in strings in JavaScript, without concatenation?