I'm trying to send an embed message with an image stored on my pc but the image appear above the embed message.
def function():
embedVar = discord.Embed(title="title", color="color")
embedVar.add_field(name = "name", value = "value", inline = False)
embedVar.add_field(name = "name", value = "value", inline = False)
embedVar.set_thumbnail(url = "attachment://filename.png")
return embedVar
embed = function()
await message.channel.send(embed = embed)
Related
I made a slash command that echoes a message. But I wanted to separate it from the main.py, and I couldn't do it. I made many commands to cogs before, but none was a Slash Command.
I used the #client.command under:
class echo(commands.Cog):
def __init__(self, client):
self.client = client
#client.command
#the rest of the code
...
I got an error message saying, "interactions.option isn't recognized". I created 3 options (1 required and the rest are optional):
#client.command(name="echo",description="testing", default_member_permissions=interactions.Permissions.ADMINISTRATOR,
options=[
interactions.Option(
name = "text",
required = True,
description = "text",
type = interactions.OptionType.STRING
),
interactions.Option(
name = "channel",
required = False,
description = "channel",
type = interactions.OptionType.CHANNEL
),
interactions.Option(
name = "timer",
required = False,
description = "timer in minutes(e.g. 20, 120)",
type = interactions.OptionType.INTEGER
)])
I've tried finding an alternative, but couldn't make it.
Also, I had an error saying that there was something about ADMINISTRATOR so I made it lowercase. all of these and more work just fine on my main bot file.
here is my whole code in the main file:
import discord, asyncio, interactions
intents = discord.Intents.all()
client = interactions.Client(token="MY TOKEN")
#client.event
async def on_ready():
print("\nBot is awake!\n")
#client.command(name="echo",description="testing", default_member_permissions=interactions.Permissions.ADMINISTRATOR,
options=[
interactions.Option(
name = "text",
required = True,
description = "text",
type = interactions.OptionType.STRING
),
interactions.Option(
name = "channel",
required = False,
description = "channel",
type = interactions.OptionType.CHANNEL
),
interactions.Option(
name = "timer",
required = False,
description = "timer in minutes(e.g. 20, 120)",
type = interactions.OptionType.INTEGER
)])
async def echo(ctx: interactions.CommandContext, text: str, channel: str = None, timer: int = None):
if channel is None and timer is None:
await ctx.send(text)
elif channel is not None and timer is None:
await channel.send(text)
await ctx.send(f"I sent your message to {channel.mention}")
elif channel is None and timer is not None:
await ctx.send(f"I will send your message after {timer} minutes.")
await asyncio.sleep(timer * 60)
await ctx.send(text)
elif channel is not None and timer is not None:
await ctx.send(f"I will send your message in {channel.mention} after {timer}")
await asyncio.sleep(timer * 60)
await channel.send(text)
client.start()
I have this issue where whenever i do
"/purge 10" i get the error "404 Not Found (error code: 10062): Unknown interaction" and it doesnt send the embed, but for some reason it seems to work whenever i do "/purge 1" and sends the embed
Here's my code:
#commands.hybrid_command(name = "purge", description = "Purges a specified number of messages")
#commands.has_permissions(manage_messages = True)
async def purge(self, ctx : commands.Context, amount : int):
creator = EmbedCreator()
embed = creator.create(
title = "Success",
description = f"```py\nCleared '{amount}' Messages ```",
color = discord.Color.green()
)
await ctx.channel.purge(limit = amount)
await ctx.reply(embed = embed, delete_after = 10, ephemeral = True) # "delete_after" deletes the embed after a certain time
The idea of this command is to send a message in a specific channel from an administration channel.
I'm trying to get the channel object from the "send" command (l.20/35) in the "send_button_response" function (l.39).
Thanks in advance
send_button = interactions.Button(
custom_id = "send_button_id",
label = "Send",
style = interactions.ButtonStyle.SUCCESS
)
cancel_button = interactions.Button(
custom_id = "cancel_button_id",
label = "Cancel",
style = interactions.ButtonStyle.DANGER
)
row_buttons = interactions.ActionRow(
components = [send_button, cancel_button]
)
#bot.command(
name = "send",
description = "Send the message in the channel of your choice",
scope = [my scope],
options = [
interactions.Option(
name = "channel",
description = "The channel in which to send the message",
type = interactions.OptionType.CHANNEL,
channel_types = [0],
required = True
),
interactions.Option(
name = "message",
description = "The message to send",
type = interactions.OptionType.STRING,
required = True
)
]
)
async def send(ctx, channel, message):
await ctx.send(content = message, components = row_buttons, ephemeral = True)
#bot.component("send_button_id")
async def send_button_response(ctx):
# here the missing instruction to send the message to the specified channel
await ctx.edit(content = "Your message has been successfully sent to the [channel] channel.")
Hi I'm trying to block a few subreddits in praw like FiftyFifty but I cant find the command for something like that this is also for a discord bot my code is here
#client.command()
async def r(ctx,subred = ""):
subreddit = reddit.subreddit(subred)
all_subs = []
top = subreddit.top(limit = 50)
for submission in top:
all_subs.append(submission)
random_sub = random.choice(all_subs)
name = random_sub.title
url = random_sub.url
if not submission.over_18:
em = discord.Embed(title = name)
em.set_image(url = url)
await ctx.send(embed = em)
else:
await ctx.send("NO")
This might be a possible solution
bannedSubreddits = ["FiftyFifty", "various", "other", "subreddits"] #Add as many subreddits as you'd like here or just add one
#client.command()
async def r(ctx,subred = ""):
subreddit = reddit.subreddit(subred)
for bannedSub in bannedSubreddits:
if subreddit == reddit.subreddit(bannedSub): #If a banned subreddit is detected, it sends what you wanted to send when you find an over 18 post
await ctx.send("NO")
return
all_subs = []
top = subreddit.top(limit = 50)
for submission in top:
all_subs.append(submission)
random_sub = random.choice(all_subs)
name = random_sub.title
url = random_sub.url
if not submission.over_18:
em = discord.Embed(title = name)
em.set_image(url = url)
await ctx.send(embed = em)
else:
await ctx.send("NO")
I know I can make a command like:
async def cat(self, ctx):
response = requests.get('https://aws.random.cat/meow')
data = response.json()
embed = discord.Embed(
title = 'Kitty Cat 🐈',
description = 'Cat',
colour = discord.Colour.purple()
)
embed.set_image(url=data['file'])
embed.set_footer(text="")
await ctx.send(embed=embed)
not my code btw
But how do I make a command to search like !image computer and it gets a random computer image from image search and sends it to the channel
You can use the Unsplash Source API, as suggested by Bagle.
#command(name = "img")
async def cat(self, ctx, arg):
embed = discord.Embed(
title = 'Random Image 🐈',
description = 'Random',
colour = discord.Colour.purple()
)
embed.set_image(url='https://source.unsplash.com/1600x900/?{}'.format(arg))
embed.set_footer(text="")
await ctx.send(embed=embed)
And execute the command with
{bot_prefix}img computers