【问题标题】:How do I automatically add people to channnel?如何自动将人员添加到频道?
【发布时间】:2021-02-07 10:43:25
【问题描述】:
我正在创建一个不和谐机器人,用户将向该机器人发送消息,该机器人会将一个人添加到私人频道。我需要隐藏它,所以不能只通过分配角色来做到这一点。有谁知道如何在 discord.py 中将人添加到频道中?
【问题讨论】:
标签:
python
discord
discord.py
【解决方案1】:
- 创建一个角色并将其命名为私有。
- 创建一个频道,只允许具有私人角色的用户发送和阅读消息。
- 编码时间
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
现在,每当用户在机器人 dm 中发送 !pvt 时,他/她都可以访问私人频道.....谢谢