不和.py,我如何让机器人创建一个通道,如果它不存在,但如果它确实存在,它将继续它的任务?

2024-03-29 12:13:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图做到当有人受到警告时(-warn@user reason)它会显示用户受到警告的内容,他们收到警告的原因和原因 然后,如果频道还没有,我希望它创建一个名为“warn logs”的频道(在输入Discord时警告日志),但如果该频道已经以该名称存在,它将继续执行它的任务,比如:哪个用户受到警告,谁受到警告,以及他们为什么受到警告,我不希望它记录任何内容,只要让人们知道警告并保存到一个频道

我已经尝试了所有我能找到的方法,但是没有任何帮助,甚至连Python Discord服务器或不和.py不一致服务器

这是warn命令本身以及到目前为止我所做的工作

@client.command()
@has_permissions(kick_members=True)
async def warn(ctx, member:discord.Member, *, arg):
 author = ctx.author
 guild = ctx.message.guild
 channel = await guild.create_text_channel('warn-logs')

 channel
 await ctx.send(f'{member.mention} warned for: {arg} warned by: {author.mention}')
 await member.send(f'{author.mention} warned you for: {arg}')
 await ctx.message.delete()

我没有收到错误消息,只不过它创建了一个名为warn logs的通道(即使已经存在同名的通道),但不发送任何消息


Tags: 用户警告内容channelargawait频道author
1条回答
网友
1楼 · 发布于 2024-03-29 12:13:04

看起来当前代码应该在调用命令的通道中发送消息。这是真的吗?在

您可以使用^{}搜索具有特定名称的频道:

@client.command()
@has_permissions(kick_members=True)
async def warn(ctx, member:discord.Member, *, arg):
    author = ctx.author
    guild = ctx.guild
    channel = get(guild.text_channels, name='warn-logs')
    if channel is None:
        channel = await guild.create_text_channel('warn-logs')
    await channel.send(f'{member.mention} warned for: {arg} warned by: {author.mention}')
    await member.send(f'{author.mention} warned you for: {arg}')
    await ctx.message.delete()

相关问题 更多 >