如何制作频道并添加用户

2024-06-23 03:39:16 发布

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

我想知道如何使用discord.py在服务器中创建一个频道,并在该频道中添加一个人并发送消息。我正在尝试制作一个ModMail bot,如果您想查看,下面是我的代码:

@bot.command()
async def new(ctx,reason):
    AuthorID = str(ctx.author.id)
    try:
        await ctx.send('@Staff <@{AuthorID}'>
        await ctx.send("Please leave your question here our support team will be with you soon!")
    except commands.MissingRequiredArgument:
        await ctx.send('You are missing a required argument `reason`')

如果你认为我不够清楚或发现任何语法/拼写错误(英语不是我的第一语言),请编辑此帖子


Tags: 代码py服务器send消息asyncbotawait
1条回答
网友
1楼 · 发布于 2024-06-23 03:39:16

您可以使用^{}创建文本频道,该频道采用overwrites参数。然后可以使用^{}创建特定于通道的权限

@client.command()
async def newticket(ctx, *, reason):
    guild = ctx.message.guild
    channel_name = f"{ctx.author.name}s Ticket"
    staff_mention, member_mention = "<@&730099343972892733>", ctx.author.mention
    
    overwrites = {
        guild.default_role: discord.PermissionOverwrite(read_messages=False),  # @everyone
        guild.me: discord.PermissionOverwrite(read_messages=True),  # Bot itself
        guild.get_member(ctx.author.id): discord.PermissionOverwrite(read_messages=False)  # Member
    }
    
    try:
        channel = await guild.create_text_channel(channel_name, overwrites=overwrites, reason=reason)
        await channel.send(f"{staff_mention} {member_mention}\n"
                           f"Please leave your question here our support team will be with you soon!")
    except commands.MissingRequiredArgument:
        await ctx.send('You are missing a required argument `reason`')

相关问题 更多 >

    热门问题