英文:
How to mention multiple users from a list in one message?
问题
await message.channel.send(f"{ ' '.join([member for member in mentionMembers])} You're now a superstar.")
英文:
I currently have a bot that goes through a CSV file with usernames in the format of username#0000 along with keywords for each user. If the bot detects a certain keyword in a message, it will send a message with all users that match that keyword mentioned in that one message. I have been able to get the code to do everything but the mentioning of all the users in one message.
This is the current code that I have but it doesn't seem to be working. Any help would be greatly appreciated.
mentionMembers = []
key1 = "superstar"
with open('csvfile.csv',) as csvfile:
reader = csv.reader(csvfile)
for row in reader:
if row[2].strip() == key1: #row 2 of the CSV is where the keyword is located
mentionMembers.append(row[0].strip()) #row 0 of the CSV is where all the usernames are located
await message.channel.send(f"{" ".join([member.mention for member in mentionMembers])} You're now a superstar)
I'm hoping to be able to get the bot to send a message like this
Bot:
@user1#0001 @user1#0002 @user1#0003 @user1#0004 @user1#0005 You're now a superstar.
If I do print (metionMembers) I get a list of all the members that matched that keyword.
答案1
得分: 1
要在Discord上提及用户,您需要他们的ID。提及的语法是:<@user_id>
。所以,不要保存用户名,保存用户ID。
假设row[0]
对应于用户ID,您可以按如下方式提及他们:
mention_members = []
key1 = "superstar"
with open('csvfile.csv',) as csvfile:
reader = csv.reader(csvfile)
for row in reader:
if row[2].strip() == key1: # CSV文件的第2列是关键词所在的位置
user_id = row[0].strip() # CSV文件的第0列是所有ID所在的位置
mention_members.append(f"<@{user_id}>")
await message.channel.send(f"{' '.join(mention_members)} You're now a superstar")
英文:
To mention a user on Discord you need their ID. The mention syntax is: <@user_id>
. So, instead of saving the username, save the user ID.
Assuming that row[0]
corresponds to the user ID, you can mention them as follows:
mention_members = []
key1 = "superstar"
with open('csvfile.csv',) as csvfile:
reader = csv.reader(csvfile)
for row in reader:
if row[2].strip() == key1: #row 2 of the CSV is where the keyword is located
user_id = row[0].strip() #row 0 of the CSV is where all the ids are located
mention_members.append(f"<@{user_id}>")
await message.channel.send(f"{' '.join(mention_members)} You're now a superstar")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论