Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

sum - How to I differentiate inputs from different members on discord?

I'm trying to record the sum of read counts from different members on a discord server. I figured out how to get the sum of the read counts, however my code is giving me the sum from everyone in the server. How do I make it count the sum for each individual member?

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = ".")

member_rc = [0]

@client.event
async def on_ready():
    print("Bot is ready.")
  
@client.command("rcc")
async def rc(ctx, *, user_input):
    """
    recieves the member's read count and outputs the sum of that member's read count.
    ex: 
    .rcc Taylor 123
    >>> Taylor just read 123 words. 
    Their total read count is 1123 words.
    
    .rcc Anna 200
    >>> Anna just read 200 words.
    Their total read count is 2200 words.
    """

    member_name, number = user_input.split(" ") #seperate the member's name and read count. 
    member_name = str(member_name)
    
    number = int(number)
    
    member_rc.append(number) #adds the member's read count to their list
    
    await ctx.send(f"{member_name} just read {number} words.
Their total read count is {sum(member_rc)} words.")
    

client.run('TOKEN')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...