【问题标题】:I want to create 'join' and 'list' command [closed]我想创建“加入”和“列表”命令 [关闭]
【发布时间】:2021-07-19 15:56:56
【问题描述】:

所以基本上我想要2个命令,即:

  1. !加入
  2. !列表

所以对于第一个命令,玩家将加入列表。一旦列表已满(10/10 玩家),玩家将无法加入。 然后,对于第二个命令,玩家将能够检查所有加入的玩家。

【问题讨论】:

  • 欢迎。 Stack Overflow 不提供代码编写服务。你知道什么并且已经拥有什么?你试过什么?您是否阅读过有关 Discord.py 的教程?
  • 我没有关于这些的信息,我请求了一些帮助,但我不明白。我需要一个例子和他们的功能。
  • 没人明白我在问什么或什么,没人回答我的问题。

标签: python database command discord.py


【解决方案1】:

嗯,你知道,我从来没有实现过 Python 机器人,所以我想我可以尝试一下,只是为了好玩。我从a tutorial 开始。最难的东西:registering an app 并管理对make the bot appear in my channel 的所有权限。

25 分钟后,我想出了我理解为您的问题:

import discord

client = discord.Client()
joined = []

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    global joined
    if message.author == client.user:
        return

    if message.content.startswith("!join"):
        if len(joined) == 10:
            await message.channel.send("List full")
            return
        if message.author not in joined:
            joined.append(message.author)
        else:
            await message.channel.send("You joined already.")

    if message.content.startswith("!list"):
        usernames = [user.name for user in joined]
        await message.channel.send("\n".join(usernames))

client.run('<your token>')

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 2013-10-12
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多