如何自动将人添加到频道?

时间:2020-10-24 16:39:17

标签: python discord discord.py

我正在创建一个不和谐的机器人,用户将向该机器人发消息,该机器人会将一个人添加到私人频道。我需要将其隐藏,因此不能仅仅通过分配角色来做到这一点。有人知道如何在discord.py中将人添加到该频道吗?

1 个答案:

答案 0 :(得分:0)

  1. 创建一个角色并将其命名为私有。
  2. 创建一个频道,仅允许具有私人角色的用户发送和阅读消息。
  3. 编写代码的时间
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

现在,每当用户将bot中的!pvt发送给dm时,他/她就可以访问私人频道.....谢谢