【发布时间】:2021-07-26 03:24:43
【问题描述】:
所以我正在尝试建立一个日志通道,每当有人被踢时,它都会在其中发布一条消息。目前我将它存储在一个 json 文件中,但我无法让它工作。有人有代码吗?这是我的:
with open('log_channels.json', 'r') as f:
log_channels = json.load(f)
@client.command()
@commands.has_permissions(administrator = True)
async def modlog(ctx, channel = None):
log_channels[str(ctx.guild.id)] = channel.split()
with open('log_channels.json', 'w') as f:
json.dump(log_channels, f)
await ctx.send(f'Mod log set to {channel}')
@client.command()
@commands.has_permissions(kick_members = True)
async def kick(ctx, member : discord.Member, *, reason = None):
await member.kick(reason = reason)
await ctx.send(embed=discord.Embed(title=f'{member} has been kicked.', color= 0xFF8633))
guild = ctx.guild
log_channels.get((guild.id) ('0'))
print (log_channels)
channel = client.get_channel(log_channels)
await channel.send(f"test")
【问题讨论】:
-
你不能让它工作是什么意思,会发生什么?有什么错误吗?
-
是的,discord.ext.commands.errors.CommandInvokeError:命令引发异常:TypeError:'int'对象不可调用
-
它打印的是哪一行,您应该在问题本身中提供整个回溯。顺便说一句,阅读stackoverflow.com/help/how-to-ask
标签: python python-3.x discord discord.py