Discord.js #everyone / #here issues with message - arguments

I have the code here for my embed announce feature, if a role is mentioned then it sends that role mention to the channel and then sends the rest of the message in an embed, i also have a variation for user mentions. How do i adapt this to do the same for #everyone & #here? they dont have ID's like roles. Either that or i cant find the ID of #everyone & #here. typing #everyone results in #everyone being returned, not an ID
if (args[1].startsWith('<#&') && args[1].endsWith('>')) {
message.channel.send(args[1])
const embed = new Discord.MessageEmbed()
.setTitle(`${(args.slice(2).join(" "))}`)
.setColor(0x320b52)
.setTimestamp()
.setFooter('Requested by ' + message.author.tag)
message.channel.send(embed);

Correct, #everyone and #here do not have IDs. Simply check whether either of them matches args[1].

Related

How do I add multiple roles form a list to a user?

I have a command that adds all the current roles of a user to a Database (MongoDB).
The code:
def add_roles_to_db(self):
check = cursor.find_one({"_id": self.ctx.author.id})
if check is None:
cursor.insert_one({"_id": self.ctx.author.id, "roles": [str(r) for r in self.ctx.author.roles[1:]]})
else:
cursor.update_one({"_id": self.ctx.author.id}, {"$set": {"roles": [str(r) for r in self.ctx.author.roles[1:]]}})
The code to get the roles:
def get_roles_from_db(self):
return cursor.find_one({"_id": self.ctx.author.id})["roles"]
When I get the roles from the DB I get a list, everything I've tried led to an error. Error: "AttributeError: 'str' object has no attribute 'id'"
if len(roles) != 0:
await author.add_roles(*roles)
I saw a other post where someone added roles via a list but that didn't work
You're passing a list of strings, not a list of Roles. Turn them into discord.Role instances using the id's first, and then pass them to add_roles.
You can get them using Guild.get_role, or Guild.roles.
await author.add_roles(*[discord.Object(role_id) for role_id in roles])
One good way of adding multiple roles to a user is to have the list of role IDs into a list. You would have to look at your code and figure out how to do that bit, as I don't know either but I reckon just append it into a list. Then interate through each item in that list (each ID) and append it.
Example code:
guild = client.get_guild(1234) #replace 1234 with your guild ID
guild = ctx.guild #this is another way of doing it, chose the one above or this
role_ids = [] #your role ids would be in this list
for id in role_ids:
role = guild.get_role(id)
await author.add_roles(role)
await ctx.send("Given you all the roles!")
I haven't tried this myself, but I don't see why it wouldn't work.
If you need any more clarification, please ask me and if this has worked, please mark it as correct! :)

Syntax for if-else branch based on user input in Bot Framework Composer

When a user is prompted with a yes or no question, each user might respond differently. Say for example, responses for yes could be yeah, why not, sure, im okay with it, yup etc and similarly to respond for no users could say nope, nah, no.
I want to send a response if the user input belongs to Yes class and send a different response if he has uttered words from No type in Bot Framework Composer.
Under Expected Responses I created entities with value to distinguish the two classes as below
-{Accept = yeah}
-{Accept = Yea}
-{Accept = yup}
-{Accept = that will work}
-{Accept = why not}
-{Accept = yep}
-{Accept = yes}
-{Accept = yeah sure}
-{Reject = No}
-{Reject = Nope}
-{Reject = nah}
screenshot of the composer window
How to write condition checking the user input with the defined class?

discord.py | how to get list user banned name and id

Discord.py
user banned by me, i want to see a list of banned user and id to remove the ban from user.
!banlist
- for made list of banned user name and id
In version 0.16.12 you can use client.get_bans(serverID) which returns a list of User objects. You can then iterate through the list and get the id and name from each user. If you wanted to have the bot list the banned users' names and ids, you could do something like:
bannnedUsers = await client.get_bans(serverID)
for user in bannedUsers:
await client.send_message(channelID, user.name + ' ' + user.id)
In the rewrite branch it's a little more complicated. You would use guild.bans() to get a list of tuples with each tuple containing a user object and a string with the reason for the ban. For the same result as before, you would do something like:
bans = await guild.bans()
for ban in bans:
await channel.send(ban[0].name + ' ' + ban[0].id)
It should be mentioned that the bot will need the ban_users permission to be able to access these coroutines.

mailchimp api delete user from list

when user unsubscribes from list he can't subscribe again with the same email address. How can allow user to resubscribe to list?
$unsubscribe = $mailChimp->call('lists/unsubscribe',array(
'id' => $list_id,
'email' => array('email' => $email),
true,
true
));
If you want to resubscribe the user later, you need to delete him, see the documentation:
When you need to remove a few subscribers, decide whether you want to delete
them yourself or unsubscribe them. Deleted subscribers can be added
back to your list, so if you need to make sure a subscriber isn't
accidentally re-added, unsubscribe them instead.
If you are using the latest mailchimp-api then you can delete the user as follows:
include 'Mailchimp.php';
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('your**api***key');
function deleteUser($email){
global $MailChimp;
//your list_id from Mailchimp
$list_id = 'your***list**id';
$subscriber_hash = $MailChimp->subscriberHash($email);
$MailChimp->delete("lists/$list_id/members/$subscriber_hash");
}
If no user with that email exists, then $MailChimp->delete() will return an array like this:
Array ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Resource Not Found [status] => 404 [detail] => The requested resource could not be found. [instance] => )
If the user was found, then the method will not return anything. Note that this does not imply that the user has been deleted, because if the user has been unsubscribed previously, then its not possible to delete him.
If you do not want to use the api, then you can also write your own custom curl command using the delete verb.
Try deleting the email from list and re-subscribe the same.
You can delete the member by setting delete_member property to true in unsubscribe method
You can do it by updating the user to a status of "pending"
Unfortunately my code is the Python api, but you should be able get the idea.
def mcResendSubscriptionSignup(self,email,audienceId):
# calculate the hash of the email address
emailHash = hashlib.md5(email.lower().encode()).hexdigest()
# get existing user, and all their data
data = self.mcClient.lists.members.get(list_id=audienceId, subscriber_hash=emailHash)
# set the user status to pending to resend subscription email
data['status'] = 'pending'
# update the data back to the user record in the audience
data = self.mcClient.lists.members.update(list_id=audienceId, subscriber_hash=emailHash, data=data)
print(f'Sent a resubscription email to {email}')
This function will resend a confirmation email to the user which he has to click on to resubscribe. Note, you need to also find your audienceId.
This is the only way that Mailchimp will allow you to re-add the user to an audience as of 2020, after an unsubscribe.
Yes, this is a pain when testing, which is why I worked on this function. Tiny bit better than doing it in the GUI interface.

EWS-managed: Fetch required and optional attendees of appointments

As far as I am now, I know how to fetch appointments from exchange server, BUT as soon as I want to see the required and optional attendees, these fields are empty ... I checked the appointment trice and there is an attendee, except me. Do I have to config Outlook differently or do I miss something?
List<Appointment> listOfAppointments = new List<Appointment>();
CalendarFolder cfolder = CalendarFolder.Bind(MyService, WellKnownFolderName.Calendar);
CalendarView cview = new CalendarView(from.ToUniversalTime(), to.ToUniversalTime());
cview.PropertySet = new PropertySet(ItemSchema.Subject);
cview.PropertySet.Add(AppointmentSchema.Start);
cview.PropertySet.Add(AppointmentSchema.End);
cview.PropertySet.Add(AppointmentSchema.Location);
cview.PropertySet.Add(AppointmentSchema.ICalUid);
cview.PropertySet.Add(AppointmentSchema.Organizer);
cview.PropertySet.Add(AppointmentSchema.IsAllDayEvent);
cview.PropertySet.Add(AppointmentSchema.DateTimeCreated);
FindItemsResults<Appointment> result = cfolder.FindAppointments(cview);
thats how I fetch the appointments, as I figured from exceptions and trail and error, I don't need to ask exchange for attendees... but maybe I am missing something.
The FindAppointments operation do not return the attendees of meetings. Instead, specify a propertyset of PropertySet.IdOnly to get only the ids of the items. Then, use the ExchangeService.LoadPropertiesForItems to perform a batch load of the properties you need.

Resources