首页 > 解决方案 > on_guild_join discord python 为什么这不起作用?

问题描述

这是我在加入服务器时启动 ofc 的代码。

    @commands.Cog.listener()
    async def on_guild_join(self, guild):
        name = str(guild.name)
        description = str(guild.description)
        member_count = str(guild.member_count)
        channel_count = str(len(guild.channels))
        id = str(guild.id)
        region = str(guild.region)
        embed = discord.Embed(title=tit + " Was invited to " + name)
        if guild.description == True:
            embed.add_field(title="Description", value=description)
        embed.add_field(title="ID", value=id)
        embed.add_field(title="Member Count", value=f"Count: {member_count}")
        embed.add_field(title="Channel Count", value=channel_count)
        embed.add_field(title="Region", value=region)
        embed.set_thumbnail(url=guild.icon_url)
        await guild_channel.send(embed=embed)

这是错误

Ignoring exception in on_guild_join
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.7/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/home/user/DiscordBots/DefaultRobloxTools/cogs/CommandEvents.py", line 58, in on_guild_join
    embed = discord.Embed(title=tit + " Was invited to " + name)
TypeError: unsupported operand type(s) for +: 'function' and 'str'

出了什么问题我不太明白这个错误信息。

标签: pythondiscord

解决方案


您以错误的格式分配字符串,它应该是

embed = discord.Embed(title=(tit + " Was invited to " + name))

代替

embed = discord.Embed(title=tit + " Was invited to " + name)

推荐阅读