python - 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'
出了什么问题我不太明白这个错误信息。
解决方案
您以错误的格式分配字符串,它应该是
embed = discord.Embed(title=(tit + " Was invited to " + name))
代替
embed = discord.Embed(title=tit + " Was invited to " + name)
推荐阅读
- wordpress - 如何在 Elementor Wordpress 上删除正文元素
- android - 测试卡总是批准不显示
- c# - 如何帮助我的控制台应用程序找到所有引用的程序集?
- ios - 从 appdelegate 启动 contentview
- performance - 更改 woocommerce 变体产品的图像背景颜色。这行得通,但是有超过 80 种不同的颜色可以让它更快
- javascript - Webpack 将错误的图像加载到 dist 目录
- java - Spring MVC Restful Application 错误 404。为什么?
- flutter - 如何在 Flutter 中将字符串格式的日期转换为时间戳
- r - 如果在用户函数中应用过滤器与没有过滤器,则某些组的结果不同
- flutter - 在有状态的小部件中,颤振字段不能是最终的