embed error occurs when guild is missing icon? - discord

line of code:
footer: {
text: `${message.guild.name}`,
icon_url: `${message.guild.iconURL({ format: "png", dynamic: true })}`,
}
the command shows the name and icon of the server in the footer of the embed and it works perfectly fine unless the guild doesn't have an icon in which case i get the error:
Invalid Form Body
embed.footer.icon_url: Not a well formed URL.
any tips?

Have you tried to do an if(){} statement? eg
if(!message.guild.iconURL){}
if(message.guild.iconURL){}
The "!" means "if not", I might be wrong but that should help you out.

Related

How to add custom "check your email" page in next-auth? (verifyRequest)

I am trying to have my own text and style there. In the documentation (https://next-auth.js.org/configuration/options#pages) it says we can add a custom page by adding verifyRequest: '/auth/verify-request' but no example
I tried to create a custom verify-request.js file with this code https://github.com/nextauthjs/next-auth/blob/1838e43b275fa36b1eb7bd046eead6795cfd0f2d/src/server/pages/verify-request.js but it do not working for me...
Is there an example ot tutorial how to do it? I searched everything all I could and nothing.
Update the pages options in [...nextauth].js (located in /pages/api/auth)
pages: {
signIn: "/auth/signin",
signOut: "/auth/signout",
error: "/auth/error", // Error code passed in query string as ?error=
verifyRequest: "/auth/verify", // (used for check email message)
// newUser: null, // If set, new users will be directed here on first sign in
},
Then create your custom page (in the above case name it "verify.js") in the location /pages/auth/ as defined above. This will override the default verify request page, and you can custom whatever you want on your verify page
When you try to add it a route like /pages/api/auth/verify it makes a problem. you should add your page directly into pages route something like /pages/verify and it should all be fine. You can use every page you'd like.

use smtp.js in react

im trying to use smtp.js in react, the problem is that when i use the code in the cdn to save it into a varible, so i can use the method send(), it says there is a syntax error, when it shouldnt happend
Line 18:83: Expected an assignment or function call and instead saw an expression no-unused-
expressions
Line 18:338: Expected an assignment or function call and instead saw an expression no-unused-
expressions
Line 18:561: Expected an assignment or function call and instead saw an expression no-unused-
expressions
Line 18:807: 'XDomainRequest' is not defined no-undef
ive been trying to import the code as a module, create a new Script tag, but nothing seems to work
You will need to include
<script src="https://smtpjs.com/v3/smtp.js"></script>
in between the <head></head> of your index.html file of your React App (you should load all scripts at the end).
Once you have done this, you can access Email by using window.Email.
Now you should be able to send an email by entering your SMTP credentials using the following code:
window.Email.send({
Host : "smtp.yourisp.com",
Username : "username",
Password : "password",
To : 'them#website.com',
From : "you#isp.com",
Subject : "This is the subject",
Body : "And this is the body"
}).then(
message => alert(message)
);
Where you put it is up to you. You could put it within a useEffect so it gets called when a particular Component is mounted to the DOM.

Is there anyway to mark images as spoiler?

The new discord update added the feature to mark images and text as spoilers for text: you just have to type || text ||. For images, there is a check mark at the bottom of the attachment prompt:
Is there a way to mark images as spoiler or is the feature too new?
This does not work:
let image = new Attachment('./img/image.jpg');
message.channel.send("|| " + image + " ||");`
a quick way of doing it would be starting the filename with SPOILER_
for example img.png would become SPOILER_img.png
message.channel.send({
files: [{
attachment: 'IMG LINK',
name: 'SPOILER_NAME.jpg'
}]
})
This is what the API has listed for the image for embeds and it doesn't seem to mention marking as a spoiler so perhaps it is yet to be added for bots. I can't find anything about spoilers in the API, maybe you'll have more luck.

How to get nightwatchjs screenshots working?

I am trying to generate a screenshot with nightwatch js , it saves a file to my location but the size is 1kb and when I try to open this there is no image. The config file is the one I got from https://www.npmjs.com/package/learn-nightwatch.
What could be the culprit?
Before you launch the screenshot, you need to be sure that the page is "ready". If you already checked that, please make sure that you added an image extension to the file name.
I'm sharing a working example:
module.exports = {
"Do a screenshot task" : function (browser) {
browser
.url("http://example.com")
.waitForElementPresent('body', 1000, 'Page loaded')
.resizeWindow(900, 3000)
.saveScreenshot('/home/yourName/path/imageName.png')
.end();
}
};
Hope it helps you.
As it stands this is how you can set up automatic screenshots in nightwatch.conf.js
"screenshots": {
"enabled": true,
"path": "./tests_output/screenshots", // location to save
"on_failure": true,
"on_error": true
}

cakephp hidden field issue

I have a problem with an input field in a view called add.ctp. When the input type is set to 'text', the program sequence is normal. But when I change the input type to 'hidden', the following error is displayed:
The request has ben black-holed. Error: The requested address was not found on this server.
mod-rewrite seems activated. Any ideas, what can be the reason for this?
There is no error with your code. CakePHP's Security component checks hidden form fields to prevent tampering by end users:
By default SecurityComponent prevents users from tampering with forms. It does this by working with FormHelper and tracking which files are in a form. It also keeps track of the values of hidden input elements. All of this data is combined and turned into a hash. When a form is submitted, SecurityComponent will use the POST data to build the same structure and compare the hash.
Use FormHelper::unlockField to make a field exempt from this feature:
$this->Form->unlockField('User.id');
This means there is an error with your code. Here is how to create hidden textbox
echo $this->Form->input('field_name', array('type'=>'hidden'));
I think It's because you are using SecurityComponent.
THe component monitor the form integrity, the hidden field shouldn't change from the user and because of that the security component "decide" that the something malicious has been done with the form for example CSRF attack and it prevent the submit. And I believe you are having some JavaScript which change the field value for some reason.
CakePHP 3
Please do not unlock fields/disable CSRF security component for any
particular action. This is important for the form security.
for those who are getting "The request has been black-holed."
,"form tampered error", "you are not authorized to access
that location." or "unexpected field in POST data". It is
mainly due to the CSRF component working as expected.
Disabling or modifying it is not a solution. Instead of disabling, please follow the right approach.
The right way should be as below:
On the Form, Add a hidden field as below.
<?= $this->Form->text('TPCalls.ID',['label' => false, 'class' => 'hidden']); ?>
before AJAX add the field
$("input[name='TPCalls[ID]']").val(event.id);
Then serialise it
var el = $("#xyzForm");
var ajaxTPCalls = el.serializeArray();
$.ajax({
type: el.attr('method'),
async: true,
url: el.attr('action'),
data: ajaxTPCalls,
dataType: "json",
cache: false,
success: function (data) {
toastr.success(data.message, data.title);
},
error: function (jqXHR) {
if (jqXHR.status == 403) {
$("body").html(jqXHR.responseText);
}
}
});
This way you do not disable CSRF or unlock any field. Any suggestions welcome.

Resources