Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何自动将人员添加到Channel?_Python_Discord_Discord.py - Fatal编程技术网

Python 如何自动将人员添加到Channel?

Python 如何自动将人员添加到Channel?,python,discord,discord.py,Python,Discord,Discord.py,我正在创建一个discord bot,其中用户将向bot发送消息,bot将向私人频道添加一个人。我需要它被隐藏,所以不能仅仅通过分配一个角色来做到这一点。有人知道如何在discord.py中向频道添加人吗 创建一个角色并将其命名为private 创建一个通道,只允许具有私有角色的用户发送和读取消息 编码时间 现在,无论何时用户将发送!机器人dm中的pvt他/她可以访问私人频道…如果你想让它进入频道,那就谢谢你了。如果用户已经在另一个频道中,则只能将其移动到该频道。 import discord

我正在创建一个discord bot,其中用户将向bot发送消息,bot将向私人频道添加一个人。我需要它被隐藏,所以不能仅仅通过分配一个角色来做到这一点。有人知道如何在discord.py中向频道添加人吗

  • 创建一个角色并将其命名为private
  • 创建一个通道,只允许具有私有角色的用户发送和读取消息
  • 编码时间

  • 现在,无论何时用户将发送!机器人dm中的pvt他/她可以访问私人频道…如果你想让它进入频道,那就谢谢你了。如果用户已经在另一个频道中,则只能将其移动到该频道。
    import discord #pip install discord.py
    from discord.ext import commands
    
    client = commands.Bot(command_prefix = '.') # your prefix
    
    @client.command() 
    async def pvt(ctx): # !pvt will be ur command 
        if str(ctx.channel.type) == 'private': # if the command if given in dm
            private_role = ctx.guild.get_role(688683645707938885) # your private channel id
            await ctx.add_roles(private_role) # give them this role
    
    client.run('your bot token') # your bot token here