Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of null (reading 'char') #5

Closed
NonameASecret opened this issue Jun 8, 2022 · 1 comment
Closed

Comments

@NonameASecret
Copy link

Given Below Error
image

My Code Below
`import { Client , LocalAuth,MessageMedia ,List} from 'whatsapp-web.js'//@ts-ignore
import { MessageEmbed,MessageButton,send,Collector} from "@deathabyss/wwebjs-sender"
import { readFileSync} from 'fs'
import qrcode from 'qrcode-terminal'

export const fileToBase64 = async( filepath:string) => {
const buffedInput = "data:image/gif;base64," + await readFileSync(filepath, 'base64')
return buffedInput
}

const client = new Client({
authStrategy: new LocalAuth(),
puppeteer: {
headless: false ,
ignoreDefaultArgs: ['--disable-extensions']
}
})

client.on('qr', (qr) => {
// Generate and scan this code with your phone
console.log('QR RECEIVED')
qrcode.generate(qr, {small: true})
});

client.on('ready', () => {
console.log('Client is ready!')
})

client.on('message', async(msg) => {
if (msg.body == '!ping') {
msg.reply('pong')
}
else if (msg.body == 'image'){
const base64Image = await readFileSync('./jagodasir.jpg',{encoding: 'base64'})
const media = new MessageMedia('image/png', base64Image)
await msg.reply(media,msg.from,{caption: 'this is my caption'})
}
else if (msg.body.startsWith('!send')){
const quoted_msg = await msg.getQuotedMessage()
if (quoted_msg){
const command_and_number = msg.body.split(' ')
const sanitized_number = command_and_number[1].toString().replace(/[- )(]/g, "")
const final_number = 94${sanitized_number.substring(sanitized_number.length - 9)}
const number_details = await client.getNumberId(final_number)
if (number_details) {
await quoted_msg.forward(number_details._serialized)
//await foward_msg_return.ms
} else {
console.log(final_number, "\nMobile number is not registered");
}
}
else{
await msg.reply('Please Reply To A Message\n\n!send 771247221')
}

}
else if (msg.body == 'list'){
    const productsList = new List(
        "Here's our list of products at 50% off",
        "View all products",
        [
          {
            title: "Products list",
            rows: [
              { id: "apple", title: "Apple" },
              { id: "mango", title: "Mango" },
              { id: "banana", title: "Banana" },
            ],
          },
        ],
        "Please select a product"
      )
    await client.sendMessage(msg.from,productsList)
}
else if (msg.body == 'button'){
    let embed = new MessageEmbed()
        .sizeEmbed(28)
        .setTitle("✅ | Successful process!")
        .setDescription("The process has been successful!")
        .addField("✔", "To confirm")
        .addField("❌", "To cancel")
        .addFields({
            name: "Now you have 2 buttons to choose!",
            value: "✔ or ❌"
    }).setFooter("WwebjsSender").setTimestamp()

    let button1 = new MessageButton().setCustomId("confirm").setLabel("✔");

    let button2 = new MessageButton().setCustomId("cancel").setLabel("❌")

    await send({
        client: client,
        number: msg.from,
        embed: embed,
        button: [button1, button2]
    })
}
else if (msg.body == 'register'){
    let someEmbed = new MessageEmbed()
        .setTitle(`1️⃣ | What is your name?`)
        .setDescription(`Please, type your name.`)
        .setFooter(`Question!`)
        .setTimestamp()
        .sizeEmbed(24);

    let anotherEmbed = new MessageEmbed()
    .setTitle(`2️⃣ | What is your age?`)
    .setDescription(`Please, type your age.`)
    .setFooter(`Question!`)
    .setTimestamp()
    .sizeEmbed(24);

    let collect = new Collector({
        client: client,
        chat: await msg.getChat(),
        time: 10000,
        number: msg.from,
        max: [20, 3],
        question: ["🔐 What is your name?", "🚨 What is your age?"],
        embed: [someEmbed, anotherEmbed]
    })
    //@ts-ignore
    collect.on("message", async (msg) => {
    let body = msg.body;
    console.log(body);
    });

    await collect.initialize();

    let resultMessageQuestion = await collect.messageQuestionCollcetor();

    let resultEmbedQuestion = await collect.embedQuestionCollector();

    console.log(resultMessageQuestion, resultEmbedQuestion);
}

})

client.initialize()`

@xXDeathAbyssXx
Copy link
Owner

The problem is here:

problem

Now change that code to this:

fixed

Code:

 let someEmbed = new WwebjsSender.MessageEmbed()
      .sizeEmbed(24)
      .setTitle(`1️⃣ | What is your name?`)
      .setDescription(`Please, type your name.`)
      .setFooter(`Question!`)
      .setTimestamp();

    let anotherEmbed = new WwebjsSender.MessageEmbed()
      .sizeEmbed(24)
      .setTitle(`2️⃣ | What is your age?`)
      .setDescription(`Please, type your age.`)
      .setFooter(`Question!`)
      .setTimestamp();

The problem was in the README.md file, in the examples, it was already fixed in version 1.93.0, update your example code and package with NPM to use it.


Another thing, the buttons won't work unless you don't use multidevice something that can't anymore, so for now you won't be able to use the buttons, until whatsapp-web.js fixes the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants