【问题标题】:How would I go about making a bot that counts how many peoples name starts with a '5' in a voice channel (discord.py)我将如何制作一个机器人来计算有多少人的名字在语音频道中以“5”开头(discord.py)
【发布时间】:2020-04-17 07:02:27
【问题描述】:

我想制作一个机器人,它可以告诉你有多少人在一个昵称以“5”开头的语音频道中,如果语音频道中的昵称少于 6 人,它会告诉你@everyone从 5 开始。如果你明白的话。我什至不知道从哪里开始。

【问题讨论】:

  • 从频道id获取频道,然后可以列出https://discordpy.readthedocs.io/en/latest/api.html#discord.VoiceChannel.voice_states的成员。

标签: python discord discord.py


【解决方案1】:

这里的关键是使用converter 从命令调用中获取VoiceChannel 对象,然后使用它查看该频道内成员的显示名称。

from discord import VoiceChannel
from discord.ext import commands

bot = commands.Bot("!")

@bot.command()
async def count_fives(ctx, channel: VoiceChannel):
    num_fives = sum(member.display_name.startswith("5") for member in channel.members)
    if num_fives < 6:
        await ctx.send(f"{ctx.guild.default_role} there are not enough people in the channel.")

bot.run("token")

【讨论】:

    猜你喜欢
    • 2018-06-16
    • 2019-04-08
    • 2021-04-29
    • 1970-01-01
    • 2021-07-06
    • 2020-08-30
    • 2021-11-19
    • 2019-05-05
    • 2020-09-26
    相关资源
    最近更新 更多