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.
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")