我正在为我的机器人制作嵌入/说命令,但我不确定如何让用户通过输入十六进制颜色来选择嵌入颜色。
我已经试过了:
@client.command(aliases=['say'])
@commands.has_permissions(manage_messages=True)
async def embed(ctx):
questions = ["Which should be the tile of the embed?",
"What should be the description?",
"What is the color of the embed? This should be a hex color."]
answers = []
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
for i in questions:
await ctx.send(i)
try:
msg = await client.wait_for('message', timeout=30.0, check=check)
except asyncio.TimeoutError:
await ctx.send('You did not answer in time. Please do it under 30 seconds next time.')
return
else:
answers.append(msg.content)
embedcolor = answers2[2]
embed = discord.Embed(description=answers[1], title=answers[0], colour=0x(embedcolor))
await ctx.send(embed=embed)
我得到这个错误:语法错误:无效的十六进制文字
我也试过让用户输入带有 0x 的十六进制颜色,但没有成功。我也尝试将此用户输入转换为整数但没有成功。
感谢您的帮助!
答案 0 :(得分:1)
是的,这是一种无效的格式,您正在做类似的事情
>>> int("ff0000", 16)
16711680
如果要将字符串转换为十六进制整数
embed = discord.Embed(..., colour=int(embedcolor, 16))
// For billing and shipping fields
add_filter( 'woocommerce_default_address_fields', 'custom_default_address_fields' );
function custom_default_address_fields( $address_fields ) {
if ( is_checkout() ) {
$address_fields['address_1']['label'] = __('Address', 'woocommerce');
$address_fields['address_1']['placeholder'] = __('Street and house number', 'woocommerce');
$address_fields['country']['label'] = __('Country', 'woocommerce');
$address_fields['postcode']['label'] = __('Postcode', 'woocommerce');
$address_fields['city']['label'] = __('City', 'woocommerce');
$address_fields['city']['placeholder'] = __('City', 'woocommerce');
}
return $address_fields;
}
add_filter( 'woocommerce_checkout_fields', 'change_checkout_fields' );
function change_checkout_fields( $fields ) {
$fields['order']['order_comments']['placeholder'] = __('Special notes');
return $fields;
}