Send Telegram bot messages with formatted text - request

I am sending Telegram bot messages in the following way:
bot_message = "Hi **James**, how are you doing?"
send_text = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&parse_mode=Markdown&text={bot_message}"
response = requests.get(send_text)
However, it seems like I'm not able to correctly format bold content within the message; how can I do that?

Use one * instead of two as detailed in the official documentation.

Related

How to (and is it possible to) make link markup work in a discord bot message?

What I'm trying to achieve is simple:
send a message like links: [link1](https://example.com/1), [link1](https://example.com/2) via a bot
get it displayed as "links: link1, link1"
In a ephemeral follow up, it works as expected:
const content = "links: [link1](https://example.com/1), [link1](https://example.com/2)"
await interaction.followUp({
ephemeral: true,
content,
})
But when I send this to a public channel like this:
await channel.send(content)
I'm getting it as plain text (links: [link1](https://example.com/1), [link1](https://example.com/2)) except the links are clickable.
Is it possible to get the same result as in an ephemeral message?
I've checked the permissions, there's only "embed" links (which sounds like "allow links in embeds", and not "allow links in messages) and it is enabled anyway on server for everyone, for the bot and in the channel. So what am I missing here?
PS Here they say that "it's only possible if the message was sent with webhook though", but I'm not quite sure what does this mean (can this be different for a public and an ephemeral message?)
You cannot use hyper links in normal messages sent by a bot. You need to use a Webhook. Considering you're using discord.js, see this guide on their documentation. When using something like that it will work as expected
const { WebhookClient } = require('discord.js');
const webhookClient = new WebhookClient({ url: "WEBHOOK_URL" });
webhookClient.send({
content: "[Hello world](https://github.com)",
username: "Webhook Username",
});
Otherwise you may use embeds and send one of these with your bot and the content you wish to have.
Right, so I've found a solution based on suggestion by Krypton. As an embed doesn't look nice and manual creation of a webhook is not an option for me, I've found that I can create a webhook on the go and use it.
After some testing, I've figured that such webhooks are also permanent (although they can be found in another part of settings than the manually created ones); they should be deleted as there's a limit of 15 webhooks – an attempt to create more fails (with DiscordAPIError[30007]: Maximum number of webhooks reached (15)).
Instead of doing
await channel.send(content)
I've put
// a guard, TypeScript requires us to be sure
if(channel instanceof TextChannel) {
const webhook = await channel.createWebhook({
// a message from a webhook has a different sender, here we set its name,
// for instance the same as the name of our bot (likewise, we can set an avatar)
name: "MyBot",
})
await webhook.send(content)
await webhook.delete()
}
This seems to be a minimal code change to get the links working.

How to add reactions to messages in discord.py without id

I am new to discord.py coding. I can't find the I'd for arrow up emoji... I've tried client.emojis and others but it doesnt work... pls help or send me all the ids or a website to see all the ids
just type your emoji in :this: form and stic an \ before the emojiname thats it!
when you send it it will come as <:something:1234567890123>
copy the numbers at the end thats your emoji id
same can be done with members and channels just instead of :this: do :#random_dude: and for channels do #general
hope this helps! Goodluck on your development!
I'm not sure what your code looks like, but if you're interacting with your 'message' asyncs you could do this.
emoji = '\N{THUMBS UP SIGN}'
# or '\U0001f44d' or '👍'
await message.add_reaction(emoji)
If you can, can you add your code so I can see where your error might be?
As zjbrown said, the thumbs up emoji can be stored in a string (and sent) using "\N{THUMBS UP SIGN}", "\U0001f44d", or "👍".
You can google a built-in emoji's name to find websites that have emoji descriptions. Sometimes these sites also have the unicode name, but this is not guranteed. If you want to send a custom emoji, you will have to find the emoji's id.
For built-in emojis, you can use RoboDanny's charinfo command (you'll have to add it to your own bot or use the RoboDanny bot in the discord.py support server) to get the unicode name.
If it is a custom emoji, you can send it in chat and get the image url (right click -> copy url). Then, look for the string of numbers before the .png and copy that. (Numbers only - don't copy the beginning of the url!) You can then send custom emojis by using the string <:[emoji name]:[emoji id]> for static emojis and <a:[emoji name]:[emoji id]> for animated emojis.

How can i edit and redesign my old embed messages

ive been texted something on my discord server before as embed. and now i just wanted to edit my old embed messages to redesign how its look by rewrite something and change colors.
how can i edit a specific embed messages by message id? i know it can edit itself by using :
first_embed = Embed(title='embed 1')
new_embed = Embed(title='embed 2')
msg = await ctx.send(embed=first_embed)
await msg.edit(embed=new_embed)
but i don't really know how to make it works. how it can edit at message ids? like checking its own id?
I am not 100% sure if I understand your question correctly, but to edit messages you could fetch them like this:
message = await ctx.fetch_message(message ID)
Or you can just use the integrated message converter in the arguments of the command.
#bot.command()
async def edit_embed(ctx, message: discord.Message):
#define the new embed here
await message.edit(embed=new_embed)
The user has to supply the message ID or message URL directly as an argument and discord.py will automatically convert it to a message object. Keep in mind that if you use the message ID, you will have to use the command in the same channel as the message you want to edit.
You have to make a new command to edit embeds and get the embed message's ID and the stuff you want to change as parameters. Then you can to Embed.copy() or Embed.to_dict() to get embed's data and then update the data you got as parameter.
An example would be:
#bot.command()
async def editembed(ctx, channel: discord.Chanel, msg_id, title, color):
msg = await channel.fetch_message(msg_id)
embed = msg.embeds[0].to_dict()
embed["title"] = title
embed["color"] = color
await msg.edit(embed = discord.Embed.from_dict())
Note: bot has no fetch message attribute so you have to either get it from channel or context (while using context you have to send the command on the same channel as the message to be edited)

How can I properly upload too long messages as a file?

I was doing some research on Discord's capabilities today, and then I noticed that the "upload as file" option is given when a message is more than 2000 characters long.
The number plays a role here, but my statement can also be wrong, the fact is that some things are posted only as a link and or then not sent at all if I raise >2000.
Here now the problem:
I am requesting data from Genius for a lyrics command. I already have some kind of override built in for when len(data["lyrics"]) is greater than 2000 "characters", that should be Discord's limit after all, otherwise the bot wouldn't be able to process the embed I am trying to send.
How can I manage that lyrics >2000 are sent as a file?
Relevant code:
if len(data["lyrics"]) > 2000:
return await ctx.send(f"<{data['links']['genius']}>"))
This is the normal request, it works too, but it just throws out the link.
I then tried to send this via discord.File with the corresponding piece of code above, does not work. (Something like file=discord.File(data) was tried too!)
Something like ctx.file.send does not work in this case either
The following posts were viewed:
Uploading a file in a embed discord.py (not a image)
Discord.py - Sending a text file on DM
Discord.py Bot sending file to Discord Channel
Python discord.py ways to split output to bypass 2000 character limit
What I want my bot to do if data["lyrics"] > 2000:
You can save the text into a io.StringIO buffer and pass that into the discord.File constructor:
from io import StringIO
text = data["lyrics"]
if len(text) > 2000:
buffer = StringIO(text)
f = discord.File(buffer, filename="lyrics.txt")
await ctx.send(file=f)

Discord.js - Get Another Channel's Topic

I'm trying to basically do what the title says.
I've tried
let channel = message.channel.get(68352726916713XXXX)
message.channel.send(channel.topic)
and stuff like that, But nothing works.
Any suggestions or answers?
If you are trying to get a channel in the same guild as the message was sent in, use message.guild.channels.get. Otherwise, use client.channels.get.
let channel = message.guild.channels.get("68352726916713XXXX");
message.channel.send(channel.topic);

Resources