Code Monkey home page Code Monkey logo

Comments (9)

yourWaifu avatar yourWaifu commented on August 17, 2024 1

I'll update the library do use a std::string, since everything else in my library uses std::string, it should be a very simple change.

from sleepy-discord.

yourWaifu avatar yourWaifu commented on August 17, 2024

This isn't a bug or an issue with startsWith, you just need to use a char*. It's better to use a std::string with the function std::string::data(). For example

std::string startMessage = "ssssss";
if (message.startsWith(startMessage.data())) {
    //code
}

However, I'm most likely going to rewrite this function to use a std::string instead as this is most likely a function made when this library was a c library.

also you should learn the difference between a char and a char*. No offense because you are new to this, just saying that it's something you should know because it's will be very good to know when working with C++.

from sleepy-discord.

DaYWhiTe avatar DaYWhiTe commented on August 17, 2024

then your example is incorrect

#include "sleepy_discord/websocketpp_websocket.h"

class myClientClass : public SleepyDiscord::DiscordClient {
public:
	using SleepyDiscord::DiscordClient::DiscordClient;
	void onMessage(SleepyDiscord::Message message) {
		if (message.startsWith("whcg hello"))
			sendMessage(message.channelID, "Hello " + message.author.username);
	}
};

int main() {
	myClientClass client("token", 2);
	client.run();
}

from sleepy-discord.

yourWaifu avatar yourWaifu commented on August 17, 2024

No, it's correct. Because that is a char* or a string literal. Or are you saying that you can't get the example to compile?

from sleepy-discord.

DaYWhiTe avatar DaYWhiTe commented on August 17, 2024

yes i tried but did not work

from sleepy-discord.

yourWaifu avatar yourWaifu commented on August 17, 2024

well I'm going to guess that you used a char, correct? If so, that would make sense why it wouldn't work, it's expecting a pointer to a array of chars. If you are talking about the example, can you give me the error with the error code and line number?

from sleepy-discord.

DaYWhiTe avatar DaYWhiTe commented on August 17, 2024

I try to do as you do, but it does not work.

C2664 Line:7
E0167 Line:7

message.h

bool startsWith(char* test);

C2664 line: 52

from sleepy-discord.

yourWaifu avatar yourWaifu commented on August 17, 2024

Oh I see, I made a mistake since std::string::data() returns a const char* instead of a char*. I'm not sure that this will work but do something like const_cast<char*>(startMessage.c_str())

from sleepy-discord.

DaYWhiTe avatar DaYWhiTe commented on August 17, 2024

thanks I am new to c ++ and I think that I can learn by writing a simple bot in the discord

from sleepy-discord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.