[英]How can I send an embed via my Discord bot, with python?
我一直在使用新的 Discord 机器人。 我已经学到了一些东西,现在我想让这些东西更加定制。
我一直在尝试让机器人发送嵌入,而不是普通消息:
@bot.command()
async def testinfo(ctx, *, arg):
idtouser = robloxpy.GetName(f'{arg}'.format(arg))
usergroups = robloxpy.GetUserGroups(f'{arg}'.format(arg))
userjoin = robloxpy.AccountAgeDays(f'{arg}'.format(arg))
userbanned = robloxpy.IsBanned(f'{arg}'.format(arg))
userval = robloxpy.GetUserLimitedValue(f'{arg}'.format(arg))
onfriends = robloxpy.GetOnlineFriends(f'{arg}'.format(arg))
frinedsoff = robloxpy.GetOfflineFriends(f'{arg}'.format(arg))
embedVar = discord.Embed(title='user: {idtouser} account stats can be folow below'.format(arg))
embedVar.add_field(name = 'User value', value= "{userval}", inline = True)
embedVar.add_field(name = 'Check if banned', value = "{userbanned}", inline = True)
embedVar.add_field(name = 'User join date (in days)', value = "{userjoin}", inline = True)
embedVar.add_field(name = 'User groups', value = "{usergroups}", inline = True)
embedVar.add_field(name = 'Users friends online', value = "{onfriends}", inline = True)
embedVar.add_field(name = 'Users offline friends', value = "{friendsoff}", inline = True)
embed.set_footer(text=ctx.author.name, icon_url = ctx.author.avatar_url)
await ctx.send(embed=embedVar)
当我尝试运行我的机器人时,我收到了语法错误:
await ctx.send(embed=embedVar)
^
SyntaxError: invalid syntax
缩进在 Python 中很重要,用于将代码块组合在一起。 如果我们以您的testinfo
function 为例,它所包含的只是:
@bot.command()
async def testinfo(ctx, *, arg):
idtouser = robloxpy.GetName(f'{arg}'.format(arg))
usergroups = robloxpy.GetUserGroups(f'{arg}'.format(arg))
userjoin = robloxpy.AccountAgeDays(f'{arg}'.format(arg))
userbanned = robloxpy.IsBanned(f'{arg}'.format(arg))
userval = robloxpy.GetUserLimitedValue(f'{arg}'.format(arg))
onfriends = robloxpy.GetOnlineFriends(f'{arg}'.format(arg))
frinedsoff = robloxpy.GetOfflineFriends(f'{arg}'.format(arg))
此后的行不被视为testinfo
function 的一部分,因为它们的缩进方式不同。 您可以通过缩进代码的 rest 来修复语法错误,如下所示:
@bot.command()
async def testinfo(ctx, *, arg):
idtouser = robloxpy.GetName(f'{arg}'.format(arg))
usergroups = robloxpy.GetUserGroups(f'{arg}'.format(arg))
userjoin = robloxpy.AccountAgeDays(f'{arg}'.format(arg))
userbanned = robloxpy.IsBanned(f'{arg}'.format(arg))
userval = robloxpy.GetUserLimitedValue(f'{arg}'.format(arg))
onfriends = robloxpy.GetOnlineFriends(f'{arg}'.format(arg))
frinedsoff = robloxpy.GetOfflineFriends(f'{arg}'.format(arg))
embedVar = discord.Embed(title='user: {idtouser} account stats can be folow below'.format(arg))
embedVar.add_field(name = 'User value', value= "{userval}", inline = True)
embedVar.add_field(name = 'Check if banned', value = "{userbanned}", inline = True)
embedVar.add_field(name = 'User join date (in days)', value = "{userjoin}", inline = True)
embedVar.add_field(name = 'User groups', value = "{usergroups}", inline = True)
embedVar.add_field(name = 'Users friends online', value = "{onfriends}", inline = True)
embedVar.add_field(name = 'Users offline friends', value = "{friendsoff}", inline = True)
embed.set_footer(text=ctx.author.name, icon_url = ctx.author.avatar_url)
await ctx.send(embed=embedVar)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.