问题是我无法将2个用户连接到该用户,因为我没有已创建频道的ID 看这段代码
async def join(ctx,i=[0],c=[0]):
author = ctx.author
guild = ctx.guild
if i[0] == 0:
channel = await guild.create_voice_channel(f"""Voice chat # {c[0]}""")
i[0] = 0
c[0]+=1
i[0] += 1
if i[0] == 2:
i[0] = 0
print(i[0])
return i[0]
有人可以帮助我吗? 进行详细说明-如果用户键入!join,它将创建一个语音通道,我希望在该通道中立即将用户发送到该通道,然后另一个用户也使用!join并将其发送到同一通道(我也通过计算加入人数来涵盖),因此,基本上,如果2个人使用该命令,我希望将他们发送到专用语音通道,如果其他2个用户也这样做,他们也将发送到自己专用的语音通道中服务器上的语音聊天。谢谢<3
答案 0 :(得分:0)
如果用户未连接到语音通道,则无法使他加入语音通道。
您唯一可以做的就是使用move_to
功能将某人转移到另一个渠道。
要跟踪哪个用户连接到某个频道,您可以使用一个字典,将频道ID作为键,将两个用户作为值:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@NoArgsConstructor @Log4j2
public class WebSecurityConfigurerImpl extends WebSecurityConfigurerAdapter {
@Autowired private UserDetailsService userDetailsService;
@Autowired private PasswordEncoder passwordEncoder;
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder);
}
@Override
public void configure(WebSecurity web) {
web.ignoring()
.antMatchers("/css/**", "/js/**", "/images/**",
"/webjars/**", "/webjarsjs");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests().anyRequest().permitAll()
.and().formLogin().loginPage("/login").permitAll()
.and().logout().permitAll();
}
}
如何使用channels = {}
async def join(ctx, i=[0], c=[0]):
author = ctx.author
guild = ctx.guild
if i[0] == 0:
channel = await guild.create_voice_channel(f"""Voice chat # {c[0]}""")
channels[channel.id] = [#Your two users]
i[0] = 0
c[0]+=1
i[0] += 1
if i[0] == 2:
i[0] = 0
print(i[0])
return i[0]
的示例:
move_to
如果要更改频道的user limit:
@commands.command()
async def move(ctx):
channel = bot.get_channel(ID) #ID must be an INT
await ctx.author.move_to(channel)
如果要检查已连接多少个members:
channel = await guild.create_voice_channel(f"""Voice chat # {c[0]}""")
await channel.edit(user_limit=2)