1- code when user send !q the bot send random of question for example : What is the most expensive metals in the world? A - Gold B - iron C - radium . if user send the true answer the bot choose him and write his name and ID if user send false answer the bot tell him the answer is false and give him just another chance.

2- is there link to teach how can I make bot with api ?

what about this code? when user send !q the bot send random of question for example : What is the most expensive metals in the world? A - Gold B - iron C - radium . if user send the true answer the bot choose him and write his name and ID if user send false answer the bot tell him the answer is false and give him just another chance.

As with any problem like this, you need to break it down into smaller problems. Design the solution for each problem to use standalone sub routines. Once you get code that doesn't work the way you'd like, we'll be more than happy to help you solve that problem. Remeber places like this site, and others are a good source of information from other people who've face that or similar problems. To paraphrase a famous saying, we help those who help themselves.

Edited 3 Years Ago by tinstaafl

// teachers I have problems with this code, when I sent !q the bot sent all questions and all choices, Please I want someone edit this bot when I sent !q sends only the first question, and when I sent !q again sends the second question . notice * I want the same command and not different * 


if (data.ToLower().StartsWith("!q"))              
             {
                 con.SendRoomTextMessage(targetid, "What is the most expensive metals in the world?");
                 con.SendRoomTextMessage(targetid, "A - Gold \nB - iron \nC - radium .");
             }
             else if (data.ToLower().StartsWith("radium") == true)
             {
                 con.SendRoomTextMessage(targetid, "true answer :d");
             }
             else 
             {
                 con.SendRoomTextMessage(targetid, "False answer :p");
             }
if (data.ToLower().StartsWith("!q"))
             {
                 con.SendRoomTextMessage(targetid, "What is the universal language ?");
                 con.SendRoomTextMessage(targetid, "A - English \nB - Arabic \nC - French .");
             }
             else if (data.ToLower().StartsWith("engilsh") == true)
             {
                 con.SendRoomTextMessage(targetid, "true answer :d");
             }
             else 
             {
                 con.SendRoomTextMessage(targetid, "False answer :p");
             }           

Edited 3 Years Ago by Zezo_1: i remember some notice

Your code seems to process some strings through a con.SendRoomTextMessage method. I can make little out of it. Try to be as clear and concise as possible if you pose a problem question. And remember, as we are no teachers, we are surely no magicians, who can look in your head, to figure out what you really want. You are doing your best, we know. Just give it another try. :)

// teachers I have problems with this code, when I sent !q the bot sent all questions and all choices, Please I want someone edit this bot when I sent !q sends only the first question, and when I sent !q again sends the second question . notice * I want the same command and not different * 

//I tried again I hope you understand my intention, I want to write code Trivia Questions with Answer : but when I send !q the bot sends all question, I want one by one question >>> I hope you you understand my intention. 

if (data.ToLower().StartsWith("!q"))              
             {                 
                 Console.WriteLine("What is the most expensive metals in the world?");
                 Console.WriteLine("A - Gold \nB - iron \nC - radium ."); 
             }
             else if (data.ToLower().StartsWith("radium") == true)
             {
                 con.SendRoomTextMessage(targetid, "true answer :d");
             }
             else 
             {
             Console.WriteLine("");
                 con.SendRoomTextMessage(targetid, "False answer :p");
             }
if (data.ToLower().StartsWith("!q"))
             {
             Console.WriteLine("What is the universal language ?");
             Console.WriteLine("A - English \nB - Arabic \nC - French .");
             }
             else if (data.ToLower().StartsWith("engilsh") == true)
             {
             Console.WriteLine("true answer");
             }
             else 
             {
             Console.WriteLine("False answer :p");
             }           

First off what you want to do will work better if you use a custom class to hold the questions and answers

    public class Question
    {
        public string NewQuestion = "";
        public Dictionary<string, bool> Answers = new Dictionary<string, bool>();
        public bool Used = false;
        public Question(string question, Dictionary<string, bool> answers)
        {
            NewQuestion = question;
            Answers = answers;
        }
    }

To initialize this in a list is simpler than it looks. After initialization of the list 2 simple methods can be used. One to send the question and the answer list, the other to verify the return answer. Here's some code that should help you get what you want. Every time your bot receives !q just call GiveTest otherwise call CheckAnswer and pass the returned string to it. I included a simple menu to test it.

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
            {
            List<Question> Questions = new List<Question>();
            Question AskedQuestion = null;            
            Dictionary<string, string> Users = new Dictionary<string, string>();
            Questions.Add(
                new Question("What is the most expensive metals in the world?", new Dictionary<string, bool>
                    {{"Gold",false},
                    {"Iron", false},
                    {"Radium", true}})
                    );
            Questions.Add(
                new Question("What is the universal language ?", new Dictionary<string, bool>
                    {{"English",true},
                    {"Arabic", false},
                    {"French", false}})
                    );

            char response = 'Z';
            while (char.ToUpper(response) != 'Q')
            {
                Console.WriteLine("A - Get Question\nQ - Quit");               
                response = Console.ReadKey().KeyChar;
                switch(char.ToUpper(response))
                {
                    case 'A':

                        Console.WriteLine(GiveTest(Questions,ref AskedQuestion));
                        Console.WriteLine(GiveTest(Questions,ref AskedQuestion));
                        string newresponse = "";
                        while(newresponse.Length <=1)
                            newresponse = Console.ReadLine();
                        Console.WriteLine(CheckAnswer(newresponse,ref AskedQuestion).ToString());
                        break;
                    case 'Q':
                        break;
                    default:
                        break;
                }
            }
        }
        public static string GiveTest(List<Question> qlist,ref Question newq)
        {
            if (newq == null)
            {
                foreach (Question q in qlist)
                {
                    if (!q.Used)
                    {
                        newq = q;
                        q.Used = true;
                        break;
                    }
                }
                if (newq == null)
                {
                    return "All questions answered";
                }
                else
                {
                    return newq.NewQuestion;
                }
            }
            else
            {
                string answerlist = "";
                for (int i = 0; i < newq.Answers.Count; i++)
                {
                    answerlist += (char)(i + 65) + " - " + newq.Answers.ElementAt(i).Key + "\n";
                }

                return answerlist;
            }
        }
        public static bool CheckAnswer(string answer, ref Question newq)
        {
            answer = char.ToUpper(answer[0]) + answer.Substring(1);
            bool rturn = false;
            if (newq.Answers.TryGetValue(answer, out rturn) && rturn)
            {
                newq = null;                
                return true;
            }
            else
            {
                newq = null;
                return false;
            }
        }
    }
        public class Question
        {
            public string NewQuestion = "";
            public Dictionary<string, bool> Answers = new Dictionary<string, bool>();
            public bool Used = false;
            public Question(string question, Dictionary<string, bool> answers)
            {
                NewQuestion = question;
                Answers = answers;
            }
        }
}

This is a very basic implementation, that shouold allow you to incorporate it into your bot.

Comments
Great effort!
This article has been dead for over six months. Start a new discussion instead.