Discord.py(Change bot’s text color)
The only solution I’ve been able to find for this (have had the same question before) was using syntax highlighting,Hope it helps, I don’t know about any other solution to really «color» texts without using syntax highlighting., Don’t quote me on that but as far I know that’s not possible? Something people use is syntax highlighting. But that’s the only thing I can imagine right now. – Vulpex Apr 6 ’19 at 14:43 , I know about syntax highlighting but that only works when a user types a message using the syntax but when i put it in my bot’s code it doesn’t work. How can put it in my code so the bot types using the syntax? – Stagger Apr 6 ’19 at 14:51
The only solution I’ve been able to find for this (have had the same question before) was using syntax highlighting
This was a way I’ve been able to include it into an embed.
async def test(ctx, *args): retStr = str("""```css\nThis is some colored Text```""") embed = discord.Embed(title="Random test") embed.add_field(name="Name field can't be colored as it seems",value=retStr) await ctx.send(embed=embed)
async def test(ctx, *args): retStr = str("""```css\nThis is some colored Text```""") await ctx.send(retStr)
Answer by Hayden Kirby
embed=discord.Embed(title='Your title', description="Your description", color=0x552E12) # your color in hexadecimal
Answer by Vivienne Gonzales
Everything is set up right, the bot is in the discord, connected, etc. This code:,I would use the discord.Color.random() function for that as it looks like the problem occurs in your color-line.,Used the discord.Color.random() function to choose a random color,Imported from discord.utils import get
import discord import random client = discord.Client() @client.event async def on_ready(): print('We have logged in as '.format(client)) color2 = "%06x" % random.randint(0, 0xFFFFFF) print(color2) @client.event async def on_message(message): if message.author == client.user: return if message.content.startswith('!randomcolor'): server = client.get_guild('') role = "Rainbow tester" color = "%06x" % random.randint(0, 0xFFFFFF) await role.edit(server=server, role=role, colour=color) await message.channel.send('Trying that. ') client.run('TOKEN')
Answer by Dior Yang
def challenge(self, ctx: Context, number: int = 1): """Show the provided challenge number.""" challenge = await get_challenge(number) description = challenge["challenge"] if len(description) > 2048: description = description[:2045] + ". " embed = Embed( title=challenge["title"], colour=Colour(0xE5E242), url=f"https://www.kingsmathsschool.com/weekly-maths-challenge/", description=description, ) embed.set_image(url=challenge["image"]) embed.set_thumbnail( url="https://pbs.twimg.com/profile_images/502115424121528320/hTQzj_-R.png" ) embed.set_author(name="King's Maths School") embed.set_footer( text=f"Challenge Released: | Category: " ) return await ctx.send(embed=embed)
Answer by Yaretzi Sherman
I was trying to make so the role RGB Changes to color red and yellow every 5 seconds
I was trying to make so the role RGB Changes to color red and yellow every 5 seconds
async def runtime_background_task(role = discord.Role): while not bot.is_closed: await bot.edit_role(server="493121776402825219", role="RGB", colour=discord.Colour(0xff0000)) await asyncio.sleep(5) await bot.edit_role(server="493121776402825219", role="RGB", colour=discord.Colour(0xffff00))
Answer by Collin Foster
Keyword argument that specifies if the account logging on is a bot token or not.,bot (bool) – Keyword argument that specifies if the account logging on is a bot token or not. Deprecated since version 1.7. ,Changed in version 1.3: Allow disabling the message cache and change the default size to 1000.,Fetches the last message from this channel in cache.
async for guild in client.fetch_guilds(limit=150): print(guild.name)
Answer by Colette Francis
The embed below is similar to what we will be making. It has a lot going on. There are multiple pictures, links, and text fields that we are able to edit.,When we request the embed now, we will see this output:,url: a string with the URL location of the picture to use for the embed picture,url: a string to set the link for the title. When you click on title in the final embed it will take you to this link
Let’s create a new command in the bot code. Call it embed . All this command will do is build the embed and send it to the channel. In the command build the initial embed object like so:
@client.command()async def embed(ctx): embed=discord.Embed(title="Sample Embed", url="https://realdrewdata.medium.com/", description="This is an embed that will show how to build an embed and the different components", color=0xFF5733) await ctx.send(embed=embed)
You have multiple options when it comes to colors. You can continue to look up HEX color codes with a tool like Google’s Color Picker, or you can use the built in colors inside discord.Color . To use the built in colors, you just use the classmethod of that color’s name. To turn the example blue, you would change it like this (change in bold):
@client.command()async def embed(ctx): embed=discord.Embed(title="Sample Embed", url="https://realdrewdata.medium.com/", description="This is an embed that will show how to build an embed and the different components", color=discord.Color.blue()) await ctx.send(embed=embed)
In action, this will look something like this:
embed.set_author(name="RealDrewData", url="https://twitter.com/RealDrewData", icon_url="https://pbs.twimg.com/profile_images/1327036716226646017/ZuaMDdtm_400x400.jpg")
If you want the author name and icon to be the person who called the command, you can pull that information from the ctx , or context of the command. ctx.author.display_name will pull the username (or nickname if they have one set for the guild) of the person who used the embed command. ctx.author.avatar_url will retrieve the URL of their avatar to use in the embed (changes in bold).
embed.set_author(name=ctx.author.display_name, url="https://twitter.com/RealDrewData", icon_url=ctx.author.avatar_url)
In action, it will look like this:
embed.set_thumbnail(url="https://i.imgur.com/axLm3p6.jpeg")
Our code will look like this to add a field:
embed.add_field(name="Field 1 Title", value="This is the value for field 1. This is NOT an inline field.", inline=False)
Field 1 is not inline, meaning that it will take up the entire line of the embed. If we want to put multiple fields next to each other, we can set inline=True . This will put the next 2 fields we create on the same line. The code will look like this:
embed.add_field(name="Field 2 Title", value="It is inline with Field 3", inline=True)embed.add_field(name="Field 3 Title", value="It is inline with Field 2", inline=True)
A simple footer is added by doing something like this:
embed.set_footer(text="This is the footer. It contains text at the bottom of the embed")
We can also do some simple string formatting to customize the text with information from ctx . To have it say “Information requested by: subpar”, we can type the sentence with <> as a placeholder for the name variable. Using the .format() string method, we can replace the placeholder with ctx.author.display_name . (Changes in bold)
embed.set_footer(text="Information requested by: <>".format(ctx.author.display_name))
Answer by Rex Wiggins
@bot.command(pass_context=True),- color=rant If its possible for this to work. I have tried it everywhere but idk where to put it. If someone can help me thanks!,Im asking where do i add it tho? i have tried every way that i know of.,You can do codeblocks in Reddit with four spaces before each line, just so you know.
This is a warn code. In this code when someone (a staff member) does .warn it will post it and dm it to me. Any who. Its so plain atm, I was wondering with the two codes i put — rant = random.randint(1, 255)