【问题标题】:How do I automatically add people to channnel?如何自动将人员添加到频道?
【发布时间】:2021-02-07 10:43:25
【问题描述】:

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

【问题讨论】:

  • 如果你的意思是让它进入你不能进入的频道。如果用户已经在另一个频道中,则只能将用户移动到该频道,member.move_to(channel)

标签: python discord discord.py


【解决方案1】:
  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

现在,每当用户在机器人 dm 中发送 !pvt 时,他/她都可以访问私人频道.....谢谢

【讨论】:

    猜你喜欢
    • 2022-09-29
    • 2019-08-31
    • 2022-07-16
    • 2018-11-14
    • 2021-11-24
    • 2017-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多