So I was trying to make embed command. Code:
#client.command()
#commands.has_permissions(administrator=True)
async def embed(ctx):
def check(message):
return message.author == ctx.author and message.channel == ctx.channel
await ctx.send('Send me your source code.')
source = await client.wait_for('message', check=check)
src = source.content
await ctx.send(embed=src)
And yeah I am wondering is there a way to convert this string to discord.Embed. I really want to send embed using source code.
What you got is a string which you can't send as an embed like this.
As you said, you have to put this into an embed.
#client.command()
#commands.has_permissions(administrator=True)
async def embed(ctx):
def check(message):
return message.author == ctx.author and message.channel == ctx.channel
await ctx.send('Send me your source code.')
source = await client.wait_for('message', check=check)
embed = discord.Embed(title="Custom Embed", description=source.content, colour=discord.Colour.red())
# You can put the colour to whatever you want with 0xHEXCODE (e.g. 0x30F90)
await ctx.send(embed=embed)
Related
I'm trying to make a bot that uses emoji to change the embed message like owo or some kind of music bot pls show me how
I'm just a guy who is interested in coding and just begin making a bot
You could catch the on_reaction_add event.
#bot.event
async def on_reaction_add(reaction, user):
if (message.author.id == bot.user.id) and (str(reaction.message.id) == "id-of-message-to-be-edited"):
reaction.message.edit(embed=Embed(title="new embed content"))
Or if you're using this in the flow of a command or a pre-called event, use discord.Client.wait_for.
#bot.command()
async def foo(ctx):
await ctx.send('Say hello by reaction with 👍!')
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '👍'
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await channel.send('Bye 👎')
else:
await channel.send('Hello 👍')
#client.event
async def on_message(message):
if message.content.startswith('!axb'):
embed = discord.Embed(title="Axb :sparkles:", description="9b9t Bot Dev", color=0xf188c9)
embed.set_image(url='insert url')
await message.channel.send(embed=embed)
#client.event
async def on_message(message):
if message.content.startswith('!opal'):
embed = discord.Embed(title="opal :sparkles:", description="9b9t Bot Dev", color=0xf188c9)
embed.set_image(url='insert url')
await message.channel.send(embed=embed)
Only the last on_message event will work, why don't you use a simple elif statement?
#client.event
async def on_message(message):
if message.content.startswith('!axb'):
embed = discord.Embed(title="Axb :sparkles:", description="9b9t Bot Dev", color=0xf188c9)
embed.set_image(url='insert url')
await message.channel.send(embed=embed)
elif message.content.startswith('!opal'):
embed = discord.Embed(title="opal :sparkles:", description="9b9t Bot Dev", color=0xf188c9)
embed.set_image(url='insert url')
await message.channel.send(embed=embed)
What im trying to do: I want my bot to send a message when its mentioned, i don't wanna use it as prefix just send a single message when mentioned.
My problem: It only reacts to the when_mentioned and will not react to the normal commands.
What i have tried:
#client.event
async def on_message(message):
if client.user.mentioned_in(message):
embed=discord.Embed(title=f"title)", color=0x7289da)
embed.set_thumbnail(url=thumbnailurl")
await message.channel.send(embed=embed)
try it:
#bot.event
async def on_message(msg):
if msg.mentions[0] == bot.user:
embed=discord.Embed(title="title",
description=f'My prefix is `{bot.get_prefix(msg)}`',
color=0x7289da)
embed.set_thumbnail(url="thumbnailurl")
await message.channel.send(embed=embed)
#client.event
async def on_message(message):
if message.mentions[0] == client.user:
embed=discord.Embed(title=f"title)", color=0x7289da)
embed.set_thumbnail(url=thumbnailurl")
await message.channel.send(embed=embed)
await client.process_commands(message)
For example, if a command had multiple arguments like:
#client.command()
async def command(ctx, channel, time, prize):
//code
How do I make it so that it asks for a different argument in every message? Something like this:
Bot: What channel?
User: (channel name)
Bot: How long?
User: (time)
Bot: What's the prize?
User: (prize)
If it helps, I'm making a giveaway bot.
Use wait_for. You can even specify how long the bot should wait.
Example:
#client.command()
async def some_command_name(ctx):
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
try:
await ctx.send("Channel?")
channel = await client.wait_for('message', check=check, timeout=60)
await ctx.send("Time?")
time = await client.wait_for('message', check=check, timeout=60)
await ctx.send("Prize?")
prize = await client.wait_for('message', check=check, timeout=60)
except asyncio.TimeoutError:
# do something
so, Ive been doing this:
from discord.ext import commands
from discord.utils import get
client = commands.Bot(command_prefix='><')
#client.event
async def on_ready():
print("I am ready Winson or not Winson :D")
#client.event
async def on_member_join(member):
channel = client.get_channel(744440768667844698)
message = await channel.send(f"Welcome to HaveNoFaith {member}, happy to be friends with you")
#client.command()
async def ping(ctx):
await ctx.send(f"Your Ping is {round(client.latency *1000)}ms")
#client.command()
async def Help(ctx2):
await ctx2.send("Hi, Im WelcomeBot v1.0...\n\nPrefix: ><\n\nCommands: ping\n help")
#and then Im trying to do like at the message "Welcome etc" if they react with the "check reaction" in that message, they will get a role in the discord server...
you can make a command named addrr(add reaction role), which will look like this -
#client.command()
#commands.guild_only()
#commands.has_permissions(administrator=True)
async def addrr(self, ctx, channel: discord.TextChannel, message: discord.Message, emoji: discord.Emoji,
role: discord.Role):
await ctx.send(f"Setting up the reaction roles in {channel.mention}.")
await message.add_reaction(emoji)
def check1(reaction, user):
return user.id is not self.client.user.id and str(reaction.emoji) in [f"{emoji}"]
while True:
try:
reaction, user = await self.client.wait_for("reaction_add", check=check1)
if str(reaction.emoji) == f"{emoji}":
await user.add_roles(role)
await message.remove_reaction(reaction, user)
else:
await message.remove_reaction(reaction, user)
except:
await message.delete()
break
It will work like this -
><addrr <#channel mention> <message ID> <Emoji> <#Role Mention>
So you can add a reaction to the messages that was sended and use wait_for to wait for a reaction on that message. I recommend you to add the timeout. If you dont want to have this timeout, simply just send these message, save it into a list and in the raw_reaction_add event check if the emoji is the one and the message is one of the messages in your list