How to change image thumb in aiogram - python

The bot receives audio from the user and needs to convert the audio image and send it back to the user
i got the id of the first audio
#dp.message_handler(content_types=['audio'], state=None)
async def get_music(message: types.Message, state: FSMContext):
async with state.proxy() as data:
audio_id = message.audio.file_id
chat_id = message.chat.id
data['audio_id'] = audio_id
data['chat_id'] = chat_id
await message.answer("send photo...")
await GetState.image.set()
and then i got the image id
#dp.message_handler(content_types=['photo'], state=GetState.image)
async def send_audio_with_thumb(message: types.Message, state: FSMContext):
async with state.proxy() as data:
audio_id = data['audio_id']
chat_id = data['chat_id']
image_file_id = message.photo[-1].file_id
await bot.send_audio(chat_id=chat_id, audio=audio_id, thumb=image_file_id)
await state.finish()
then i sent them via send_audio command but the audio image didn't change

Related

Update an embed message that already exists in Discord

I want to update an embed message that my bot has already written in a specific channel, how can I do that? If i try to use message.edit it givesthis error: discord.errors.Forbidden: 403 Forbidden (error code: 50005): Cannot edit a message authored by another user
import discord
import json
from discord.ext import commands
def write_json(data,filename="handle.json"):
with open (filename, "w") as f:
json.dump(data,f,indent=4)
class Handle(commands.Cog):
def __init__(self, client):
self.client=client
#commands.Cog.listener()
async def on_ready(self):
print("Modulo_Handle: ON")
#commands.command()
async def Handlers(self,ctx):
with open('handle.json','r') as file:
data = json.load(file)
embed = discord.Embed.from_dict(data)
await ctx.channel.send(embed=embed)
file.close()
#commands.Cog.listener()
async def on_message(self, message):
if str(message.channel) == "solaris™-handle":
author = message.author
content = message.content
user = str(author)
with open ("handle.json") as file:
data = json.load(file)
temp = data['fields']
y={"name":user[:-5],"value":content}
temp.append(y)
write_json(data)
updated_embed = discord.Embed.from_dict(data)
await message.edit(embed=updated_embed)
file.close()
def setup(client):
client.add_cog(Handle(client))
msg_id = 875774528062640149
channel = self.client.get_channel(875764672639422555)
msg = await channel.fetch_message(msg_id)
with open('handle.json','r') as file:
data = json.load(file)
embed = discord.Embed.from_dict(data)
await msg.edit(embed=embed)
Fixed adding this code below write_json(data) and remove
updated_embed = discord.Embed.from_dict(data) await message.edit(embed=updated_embed)

How to make a set logging channel command

Im trying to make a public bot, and i would want this ticket system witha logging channel it already has a logging channel but how can i modify this to make a command that sets the logging channel?
# --- Ticket Open ---
#client.command()
#commands.guild_only()
async def ticket(ctx):
if ctx.channel.type != discord.ChannelType.private:
channels = [str(channel) for channel in client.get_all_channels()]
if f'ticket-{ctx.author.id}' in channels:
await ctx.message.delete()
else:
ticket_channel = await ctx.guild.create_text_channel(f'ticket-{ctx.author.id}')
await ticket_channel.set_permissions(ctx.guild.default_role, send_messages=False, read_messages=False)
await ticket_channel.set_permissions(ctx.author, send_messages=True, read_messages=True, add_reactions=True, embed_links=True, attach_files=True, read_message_history=True, external_emojis=True)
embed = discord.Embed(color=10181046, description=f'Please enter the reason for this ticket, type `-close` if you want to close this ticket.')
embed.set_thumbnail(url='')
await ticket_channel.send(f'{ctx.author.mention}', embed=embed)
await ctx.message.delete()
logchannel = await client.fetch_channel('850364625479532545')
embed = discord.Embed(title="Ticket Created",
description="",
color=discord.Colour.green())
embed.add_field(name=f'**By:** {ctx.author}',value= f'**ID:** {ctx.author.id}')
await logchannel.send(embed=embed)
#--- Ticket Close ---
#client.command()
#commands.guild_only()
async def close(ctx):
print(f'{ctx.author} | {ctx.author.id} -> {client.command_prefix}close')
if ctx.channel.type != discord.ChannelType.private:
admin_roles = [834126146215477348,835608325273157733,838859643224326144,835582821221138472,835914273402126376]
if ctx.channel.name == f'ticket-{ctx.author.id}':
await ctx.channel.delete()
elif admin_roles and 'ticket' in ctx.channel.name or ctx.author.id in administrator_ids and 'ticket' in ctx.channel.name:
await ctx.channel.delete()
else:
await ctx.message.delete()
logchannel = await client.fetch_channel('850364625479532545')
embed = discord.Embed(title="Ticket Closed",
description="",
color=discord.Colour.red())
embed.add_field(name=f'**By:** {ctx.author}',value= f'**ID:** {ctx.author.id}')
await logchannel.send(embed=embed)
Tip: if you want to create a public bot don't use handwritten channel id, you'd better save to file for all servers in json file and set it with command.
For example this:
{
"server identifier": "system channel identifier",
...
}
I don't know what's wrong with the code.

How can I send my bot's response in Embed in discord.py

I know how to send embeds in discord.py but I am a little bit confused about this code
Please, anyone, help me with a sample of code for this command.
#client.command()
async def wanted(ctx, user: discord.Member = None):
if user == None:
user = ctx.author
wanted = Image.open("wanted.jpg")
asset = user.avatar_url_as(size = 128)
data = BytesIO(await asset.read())
pfp = Image.open(data)
pfp = pfp.resize((257, 257))
wanted.paste(pfp, (99, 201))
wanted.save("profile.jpg")
await ctx.send(file = discord.File("profile.jpg"))
To send a local image in an embed:
file = discord.File("some_file_path", filename="image.png")
embed = discord.Embed()
embed.set_image(url="attachment://image.png") # Same name as in the file constructor
await ctx.send(file=file, embed=embed)
To add the pfp of the invoker to an embed
embed = discord.Embed()
embed.set_image(url=ctx.author.avatar_url)
await ctx.send(embed=embed)

Nuke command in discord.py

I've made a nuke command in my discord bot, but I have 2 problems with it. First is how can i send a message to just created channel, and second is how can I make channel in same position as "original".
Here's my code:
# nuke
#client.command()
#commands.has_permissions(ban_members=True)
async def nuke(ctx):
embed = discord.Embed(
colour=discord.Colour.blue,
title=f":boom: Channel ({ctx.channel.name}) has been nuked :boom:",
description=f"Nuked by: {ctx.author.name}#{ctx.author.discriminator}"
)
embed.set_footer(text=f"{ctx.guild.name} • {datetime.strftime(datetime.now(), '%d.%m.%Y at %I:%M %p')}")
await ctx.channel.delete(reason="nuke")
await ctx.channel.clone(reason="nuke")
await ctx.send(embed=embed)
You can store the cloned channel in a variable:
# nuke
#client.command()
#commands.has_permissions(ban_members=True)
async def nuke(ctx):
embed = discord.Embed(
colour=discord.Colour.blue,
title=f":boom: Channel ({ctx.channel.name}) has been nuked :boom:",
description=f"Nuked by: {ctx.author.name}#{ctx.author.discriminator}"
)
embed.set_footer(text=f"{ctx.guild.name} • {datetime.strftime(datetime.now(), '%d.%m.%Y at %I:%M %p')}")
await ctx.channel.delete(reason="nuke")
channel = await ctx.channel.clone(reason="nuke")
await channel.send(embed=embed)
The channel should be created in the same position as the original one, if not:
pos = ctx.channel.position
await ctx.channel.delete()
channel = await ctx.channel.clone()
await channel.edit(position=pos)

Discord webhook with embed

I made a few commands for my discord bot. When I Send the command .y or .j6 for the 2nd time it pushes the first one with the second. How can I fix this?
(I need to post more details but i dont have them so i write this so i can post this so dont read this because this is trash)
import discord
from discord.ext import commands
from discord_webhook import DiscordWebhook, DiscordEmbed
async def on_ready():
print('Bot is ready.')
client = commands.Bot(command_prefix= '.')
webhook_urls = ['https://discordapp.com/api/webhooks/694265463936647289/zwRbi6A_jHp9r7kbTwOlWir9rS3-cXtMa6XLHHmrzwgyJtQaLPiisbSQBRgq7v39F6MG', 'https://discordapp.com/api/webhooks/699705671440138291/52awf2UE2TgVhumFQKp8ZOo-lz4iBtjt786NC1W1TDElAKCx4spXLP3RNi7O4avuQpHo']
webhook = DiscordWebhook(url=webhook_urls)
#client.command()
async def ping(ctx):
await ctx.send(f'Pong! {round(client.latency * 1000)}ms')
#client.command()
async def raffle(ctx, link, store, sneaker, raffletype ):
channel = client.get_channel(642837709198721034)
embed = discord.Embed(
title=sneaker,
description=store,
url=link,
colour=discord.Colour.blue()
)
embed.add_field(name="Release type", value=raffletype)
embed.set_footer(text='The Hypesply | Chip#4600')
await channel.send(embed=embed)
#client.command()
#commands.has_role('Owner')
async def j6(ctx, link, store, raffletype ):
embed = DiscordEmbed(
title="Nike AirJordan 6 'DMP'",
url=link,
colour=discord.Colour.blue()
)
embed.add_embed_field(name="Store", value=store)
embed.add_embed_field(name="Release type", value=raffletype)
embed.set_thumbnail(url="https://static.sneakerjagers.com/products/660x660/126329.jpg")
embed.set_footer(text='The Hypesply | Chip#4600')
webhook.add_embed(embed)
webhook.execute()
#client.command()
#commands.has_role('Owner')
async def y(ctx, link, store, raffletype):
embed = DiscordEmbed(
title="Adidas Yeezyboost 350 V2 'Linen'",
url=link,
colour=discord.Colour.blue()
)
embed.add_embed_field(name="Store", value=store)
embed.add_embed_field(name="Release type", value=raffletype)
embed.set_thumbnail(url="https://static.sneakerjagers.com/products/660x660/155433.jpg")
embed.set_footer(text='The Hypesply | Chip#4600')
webhook.add_embed(embed)
webhook.execute()```

Categories

Resources