[英]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.